title: jQuery Username Availability - Both Return "Not Available"
body: <p>After following replies to a previous question on here, I used jQuery to return whether a username was available or not, I found some code on a site, which showed me how to do it. From what I can see, the code seems to be structured correctly, and is connecting to the Database, however even if the name isn't in the Database it returns that it is not Available.</p>
  
  <p>Here is the jQuery(And Registration form) which is included in the register.php file (Will link below jQuery). </p>
  
  <pre class="lang-js prettyprint-override"><code>&lt;div class="registration"&gt;
    &lt;h3&gt;Register - Create a new Account&lt;/h3&gt;
  
    &lt;form action="confirm-registration.php" method="POST"&gt;
      &lt;input type="text" name="create-username" id="username" placeholder="Username" maxlength="25" /&gt;&lt;input type='button' id='check_username_availability' value='Check Availability'&gt;
  &lt;div id='username_availability_result'&gt;&lt;/div&gt;  &lt;br /&gt;
      &lt;input type="password" name="create-password" placeholder="Password" /&gt; &lt;br /&gt;
      &lt;input type="password" name="confirm-password" placeholder="Confirm Password" /&gt; &lt;br /&gt;
      &lt;input type="email" name="create-email" placeholder="E-mail Address" maxlength="45" /&gt; &lt;br /&gt;
      &lt;input type="submit" value="Complete Registration" /&gt;
    &lt;/form&gt;
  
    &lt;form&gt;
      &lt;input type="submit" value="Cancel" /&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCJnj2nWoM86eU8Bq2G4lSNz3udIkZT4YY&amp;sensor=false"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="/check-user.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function() {
  
          //the min chars for username
          var min_chars = 3;
  
          //result texts
          var characters_error = 'Minimum amount of chars is 3';
          var checking_html = 'Checking...';
  
          //when button is clicked
          $('#check_username_availability').click(function(){
              //run the character number check
              if($('#username').val().length &lt; min_chars){
                  //if it's bellow the minimum show characters_error text '
                  $('#username_availability_result').html(characters_error);
              }else{
                  //else show the cheking_text and run the function to check
                  $('#username_availability_result').html(checking_html);
                  check_availability();
              }
          });
  
    });
  
  //function to check username availability
  function check_availability(){
  
          //get the username
          var username = $('#username').val();
  
          //use ajax to run the check
          $.post("check_username.php", { username: username },
              function(result){
                  //if the result is 1
                  if(result &gt; 0){
                      //show that the username is available
                      $('#username_availability_result').html(username + ' is Available');
                  }else{
                      //show that the username is NOT available
                      $('#username_availability_result').html(username + ' is not Available');
                  }
          });
  
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>
  The code below links in the final file relevant to this - check-username.php. This is the file that queries the database with the username and then returns it. I will link that below this php.
  </p>
  
  <pre><code>&lt;?php
      include '../connect.php';
  
      if (isset($_SESSION['signed_in']) &amp;&amp; $_SESSION['signed_in'] == true ) {
        header('Location : http://localhost/blog');
      } else {
        echo include 'registration_form.php';
        require 'check_username.php';
      }
   ?&gt;
  </code></pre>
  
  
  
  <pre class="lang-html prettyprint-override"><code>&lt;?php
      $username = mysql_real_escape_string(isset($_POST['create-username']));
  
      //mysql query to select field username if it's equal to the username that we check '
      $result = mysql_query('SELECT user_name from users where user_name = "'. $username .'"');
  
      //if number of rows fields is bigger them 0 that means it's NOT available '
      if(mysql_num_rows($result) &gt; 0){
        //and we send 0 to the ajax request
        echo 0;
      } else {
        //else if it's not bigger then 0, then it's available '
        //and we send 1 to the ajax request
        echo 1;
      }
  </code></pre>
  
  
  
  <p>Any help with this would be appreciated, this isn't my code and I've not done much jQuery, so after trying a few things I'm now at a complete loss on how to fix it.</p>
  
  <p>Thanks,
  Ben</p>