Help with validation with "jquery validate"
Hello friends. I am denying with the validation with jquery validate to know if a user exists in the database at login. I am getting an "undefined" error, I don't know if the error will be in the json handling. I hope you can help me.
html:
<form method="post" name="myemailform" id="myemailform" action="#" >
<p>
<label for='email'>Email Address:</label><br>
<input type="text" name="email" id="user_nickname" >
</p>
<input type="submit" name='submit' value="Post it !">
</form>
js:
$("#myemailform").validate({
rules: {
'email':{
required: true,
email: true,
remote:{
url: "chek-email.php",
type: "post"
}
}
},
messages: {
email:
{
required: "The Email is required!",
email: "Please enter a valid email address!",
remote: "The email is already in use by another user!"
}
},
submitHandler: function (form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
}
});
chek-email.php:
function isset_email($email){
global $conn;
$email = trim($email);
$query = "SELECT COUNT(*) AS num FROM tb_usuario WHERE mailUsuario='" .mysqli_real_escape_string($conn,$email). "'";
$result = mysqli_query($conn,$query);
$row = mysqli_fetch_array($result);
if($row['num']>=1){
return TRUE; // Si el usuario existe
}
else{
return FALSE; // Si el usuario no existe
}
}