This is my php:
header('Content-type: application/json');
try {
$conn = new PDO('mysql:host=localhost;dbname=grand_debrouillage', 'gd_user', 'gd_p455w0rd');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (!empty($_POST['email'])) {
$stmt = $conn->prepare('SELECT id FROM users WHERE courriel = :courriel');
$stmt->bindParam(':courriel', $_POST['email'], PDO::PARAM_INT); // <-- Automatically sanitized by PDO
$stmt->execute();
if ($stmt->rowCount() == 0) {
echo json_encode(true); //good to register
}
else {
echo json_encode(false); //already registered
}
}
else {
echo json_encode(false); //invalid post var
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
This is my my js
$('#form').validate({ // initialize the plugin
rules: {
prenom: {required:true},
nom: {required:true},
email: {
required:true,
email:true,
remote: {
type: 'POST',
url:"email_check.php"
}
},
...