jquery validate remote method usage to check if username already exists

Solutions on MaxInterview for jquery validate remote method usage to check if username already exists by the best coders in the world

showing results for - "jquery validate remote method usage to check if username already exists"
Bloom
06 May 2016
1//HTML
2$("#signupForm").validate({
3  rules: {
4    username: {
5      required: true,
6      minlength: 3,
7      remote: "check-username.php"
8    }
9  },
10  messages: {
11    username:{
12      remote: "This username is already taken! Try another."
13    }
14  }
15});
16
17//PHP code of check-username.php
18<?php
19
20header('Content-type: application/json');
21$request = $_REQUEST['username'];
22
23$query = mysql_query("SELECT * FROM mmh_user_info WHERE username ='$username'");
24$result = mysql_num_rows($query);
25if ($result == 0){
26$valid = 'true';}
27else{
28$valid = 'false';
29}
30echo $valid;
31exit;
32?>