title: Php query using jquery
body: <p>I'm working on a webpage in which, when the user checks a checkbox, calling a PHP function to query the table if the user exists. If so, it then displays the button to go to next page.</p>
  
  <p>So far I've tried this. I am sure that my php is working fine I checked my result variable returns 0 when user exists, but for some reason it is not executing the <code>if</code> statement.</p>
  
  <pre><code>$(document).ready(function() {
  
      $('#submit').hide();
      $('#mobiletask').change(function(){
  
          if($('#mobiletask').attr('checked'))
          {
              check_availability();
              // $( "#notifyresult" ).html( "&lt;p&gt;Awesome, we'll send you an email!&lt;/p&gt;" );
          }
      });
  });
  
  
  //function to check username availability  
  function check_availability(){  
  
      //get the username  
      // var username = $('#username').val();  
      var username = '&lt;?php  echo $_GET['id']; ?&gt;';
  
      $.post("check_username.php", { username: username }, function(result){  
  
          //if the result is 1 
          if(result == 1){  
  
              //show that the username is available  
              $("#errormessage").html('&lt;p&gt;PLease complete the task before proceeding&lt;/p&gt;'); 
          }
          else if(result == 0) {  
              //show that the username is NOT available 
              $('#submit').show();
          } 
      });  
  } 
  </code></pre>
  
  <p><code>checkusername.php</code></p>
  
  <pre><code>    $username = mysql_real_escape_string($_POST['username']);  
  
       //mysql query to select field username if it's equal to the username that we check '  
        $result = mysql_query('select studentId from smartphone_scores where studentId = "'. $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>