Basically, I want to check if the email exists in the DB automatically. The function will not work when connection.php
& mysqli
queries was inserted.
HTML:
<input type="email" name="email" class="formEmail">
JS:
$( document ).ready(function() {
$('.formEmail').on('change', function() {
//ajax request
$.ajax({
url: "queries/checkEmail.php",
data: {
'email' : $('.formEmail').val()
},
dataType: 'json',
success: function(data) {
if(date == true) {
alert('Email exists!');
}
else {
alert('Email doesnt!');
}
},
error: function(data){
//error
}
});
});
});
PHP:
require_once("../connection.php");
$userEmail = $_GET['email'];
$checkEmail=mysqli_query($con, "SELECT email from accounts WHERE email='$userEmail'");
if (mysqli_num_rows($checkEmail) == 1) {
$response = true;
} else {
$response = false;
}
echo json_encode($response);