Answers for "jQuery Validate remote method usage to check if username already exists"

0

jQuery Validate remote method usage to check if username already exists

//HTML
$("#signupForm").validate({
  rules: {
    username: {
      required: true,
      minlength: 3,
      remote: "check-username.php"
    }
  },
  messages: {
    username:{
      remote: "This username is already taken! Try another."
    }
  }
});

//PHP code of check-username.php
<?php

header('Content-type: application/json');
$request = $_REQUEST['username'];

$query = mysql_query("SELECT * FROM mmh_user_info WHERE username ='$username'");
$result = mysql_num_rows($query);
if ($result == 0){
$valid = 'true';}
else{
$valid = 'false';
}
echo $valid;
exit;
?>
Posted by: Guest on May-20-2020

Code answers related to "jQuery Validate remote method usage to check if username already exists"

Code answers related to "Javascript"

Browse Popular Code Answers by Language