I\'m new to JQuery and attempting to write a script to check username availability. My problem is that no matter what I type, I always get back \"This username is already in
You could use the following, just change it for your user name (I use the email address as the user name. I use an empty table cell id="emailError" to hold the message.
The jQuery:
$('#email').keyup(function(){
$.ajax({
type: 'POST',
url: 'ajax.checkEmail.php',
data: {e:$('#email').val()},
success: function(data){
if(data == 'true'){
$('#emailError').html('This email is already used');
}else{
$('#emailError').html('');
}
}
})
});
The PHP (ajax.checkEmail.php):
include('inc.php');
$query = 'SELECT COUNT(*) FROM tblcustomers WHERE email = "'.$_POST['e'].'"';
$result = $dbO->getSingleResult($query);
if($result > 0)
print 'true';
else
print 'false';