I have a bit of an issue getting jQuery Validation to check if an email address already exists in a mysql table.
Every time I submit the form, it tells me the email already exists, even though I know it doesn't.
Here's the code I have:
validation.js
$(document).ready(function () {
$('#signup').validate({
errorLabelContainer: #cs-error-note,
wrapper: li,
rules: {
email: {
required: true,
email: true,
remote: {
url: check-username.php,
type: post
}
}
},
messages: {
email: {
required: Please enter your email address.,
email: Please enter a valid email address.,
remote: Email already in use!
}
},
submitHandler: function(form) {
form.submit();
}
});
});
check-username.php
<?php
require('../../private_html/db_connection/connection.php');
$conn = new PDO(mysql:host=$servername;dbname=$dbname, $username, $password);
$query = $conn->prepare(SELECT * FROM 'user_accounts' WHERE email = ' . $_POST['email'] . ');
$query->execute();
if( $query->rowCount() > 0 ){
echo 'true';
}
else{
echo 'false';
}
?>
Your help is much appreciated!