I want to check if a username exists in the database using jQuery.validate, so here is what I still have:
JQuery
$("#signupForm").validate({ rules: { username: { required: true, minlength: 3, remote: "check-username.php" } }, messages: { username:{ remote: "This username is already taken! Try another." } } });
check-username.php:
<?php require_once "./source/includes/data.php"; header('Content-type: application/json'); $name = mysql_real_escape_string($_POST['username']); $check_for_username = mysql_query("SELECT username FROM mmh_user_info WHERE username='$name'"); if (mysql_num_rows($check_for_username) > 0) { $output = true; } else { $output = false; } echo json_encode($output); ?>
This code always shows an error that the username is accepted, even if it is not.
I am using jQuery Mobile 1.9.1
Thanks in advance.
source share