I'm trying to check if an email exists in the system, before a user is created. I'm using PHP and jQuery (AJAX, plugin).
Even though there is none in the database with the same email, my script writes that there is an existing identical e-mail. But it still creates the user (which it should).
If there is an existing e-mail, it's not creating the user, and it's writing the correct error message.
I don't know if it's my AJAX that's wrong?
My PHP:
$check_email = mysql_query("SELECT * FROM table WHERE email='$email'");
$email_count = mysql_num_rows($check_email);
if($email_count>0){
echo "Email exists";
return false;
}
And my jQuery:
$(function() {
$("#goNewUser").click(function() {
// validate and process form here
var username = $("input#username").val();
if(username == "") {
$("input#username").focus();
return false;
}
var email = $("input#email").val();
if(email == "") {
$("input#email").focus();
return false;
}
var password = $("input#password").val();
if(password == "") {
$("input#password").focus();
return false;
}
var salt = $("input#salt").val();
if(salt == ""){
$("input#username").focus();
return false;
}
var dataString = 'username=' + username + '&email=' + email + '&password=' + password + '&salt=' + salt;
//alert (dataString);
$.ajax({
type: "POST",
url: "includes/classes/handler.php?do=addLogin",
data: dataString,
success: function(returnedData){
if(returnedData == ''){
$('.sideBarNewUserWrap').fadeOut();
} else {
$('.errorMessage').fadeIn().html(returnedData);
}
}
});
return false;
});
});