I have a form and I am using jQuery validate plugin.
I am also using remote to check if the username and email are available or not but I always get false back from the script.
here is the jquery validation part:
$(document).ready(function () {
$('#registration').validate({
rules: {
email: {
email: true,
remote:{
url: "./php/checkemail.php",
type: "POST",
}
},
username: {
minlength: 4,
maxlength: 16,
remote: {
url: "./php/checkusername.php",
type: "POST",
}
},
messages: {
email: {
email: "Please enter a valid e-mail address.",
remote: "This email is already registered.",
},
username: {
minlength: "Your username must be at least 4 characters long but less than 16",
maxlength: "Your username must be at least 4 characters long but less than 16",
remote: "This username is already registered.",
},
submitHandler: function(form) {
$('#registration').ajaxSubmit();
return false;
},
});
});
and here is the checkemail.php file:
$mysqli = mysqli_init();
if(isset($_POST['email'])) {
$email = mysqli_real_escape_string(strtolower($_POST['email']));
$check= mysqli_query("SELECT * FROM users WHERE LOWER email = '$email'");
if(mysqli_stmt_num_rows($check)!=0) {
echo json_encode(false);
} else {
echo json_encode(true);
}
}
Can anyone tell me please what I did wrong and how to fix it?
Also, even if I change the script to send me true, the remote message from the validation script doesn't appear on my form.