title: jQuery Validate remote method usage to check if username already exists
body: <p>I want to validate if username exists in database using jQuery.validate so here's what I have so far:</p>
  
  <p>jQuery:</p>
  
  <pre><code>    $("#signupForm").validate({
          rules: {
              username: {
                  required: true,
                  minlength: 3,
                  remote: "check-username.php"
                  }
              },
          messages: {
              username:{
                  remote: "This username is already taken! Try another."
              }
          }
    });
  </code></pre>
  
  <p>check-username.php:</p>
  
  <pre><code>&lt;?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) &gt; 0) {
      $output = true;
  } else {
      $output = false;
  }
  echo json_encode($output);
  ?&gt;
  </code></pre>
  
  <p>This code always shows an error that the username is taken even if it's not.</p>
  
  <p>I'm using jQuery Mobile 1.9.1</p>
  
  <p>Thanks in advance.</p>