SMS Website , Barred or Not Barred Php
Im starting a sms website and im nearly complete - just one feature i need to add into it and im a but stuck,
Ive got a form that they fill out with their name , number and message and then they click send , that gets sent to another form to proceed with the validation of the message etc,
What i need is to be able to crosslist the number field against a known database list of blacklisted numbers that dont want messages sent to their phone.
This is the checking code at the moment: so if you imagine at the moment there is a button called send and a button called check number.
When you click check number it will either find the number or not , I know its strange having 2 numbers but its the way its built at the moment.
NOW , instead of it saying number not found id like it to enable the send button , I know how to disa开发者_运维知识库ble it via disabled="disabled" but i dont know how to automate it , Id like the button greyed out when users go to the form , then when this checks the numbers id like it to ungrey the button if the number isnt in the list.
<?php
$con = mysql_connect("localhost","xxx_members","xxxx");
if(!$con)
{
die("could not connect:".mysql_error());
}
mysql_select_db("xxx_number",$con);
$mobile = $_GET['c'];
$count = mysql_num_rows(mysql_query("select * from mobileCheck where number = '".$number."'"));
if($count > 0) {
echo "Number found">";
}else{
echo "Number Not Found">";
}
?>
Any help on this would be appreciated , its starting to drive me up the wall
Thanks
First of all you need to correct your php code that you listed:
if($count > 0) {
echo "1";
}else{
echo "0";
}
Now you need to make and ajax call to the above file when the first button is clicked using JS and collect back the server response, i.e, either 1 or 0. Now you need to do a client side checking of the server response and enable the button dynamically using javascript it the server echoed 1.
number_check.php
<?php
$con = mysql_connect("localhost","xxx_members","xxxx");
if(!$con)
die("could not connect:".mysql_error());
mysql_select_db("xxx_number",$con);
$number = $_POST['number'];
$count = mysql_num_rows(mysql_query("select * from mobileCheck where number = '".$number."'"));
if($count > 0)
{
echo 1;
}else{
echo 0;
}
?>
html:
<input type="text" id="number" value="" />
<input type="button" id="btn_send" value="Send SMS" disabled />
javascript - jQuery:
$.post("number_check.php", { number: $('#number').value},
function(data) {
if (data == '1')
$('#btn_send').disabled = false;
else
$('#btn_send').disabled = true;
});
I'm sorry but I didn't test the solution, but I think this is your answer. You will of course need to test the number with the db on post, because enabling the button is simple and could be a possible flaw, so you cannot rely on disabling the button, it is only for ergonomic purposes.
精彩评论