Hi
I must now seek help after too many hours of failure.
I'm using a basic registration form with Ajax, but the form is not connecting to the database. I'm obviously overlooking something.
So here's the field i want to validate. obviously, its the username.
Username:<input type="text" name="user" id="user" maxlength="30">
<span id="msgbox" style="display:none"></span>
then i use jquery, here's the code:
$(document).ready(function()
{
$("#user").blur(function()
{
//remove all the class add the messagebox classes and start fading
$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
//check the username exists or not from ajax
$.post("user_availability.php",{ user_name:$(this).val() } ,function(data)
{
if(data=='no') //if username not avaiable
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1);
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1);
});
}
});
});
});
and i have this code, user_availability.php:
mysql_connect(localhost,$user,$password);
or die('There is error to connect to server:-'.mysqli_connect_error());
$db_selected = mysql_select_db($database);
$user_name=$_POST['user_name'];
$sql = "select * from members where username='$user_name'";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
$existing_users[] = $row['username'];
}
if (in_array($user_name, $existing_users))
{
//user name is not availble
echo "no";
}
else
{
//user name is available
echo "yes";
}
I get no database errors. The form will be more substantial, but I can't get it to work with this field. Any suggestions? Any help? Thanks very much...