title: JavaScript Username authentication
body: <p>The following represent my registration link which lead to open a modal:</p>
  
  <pre><code>&lt;a href="#registermodal" data-toggle="modal"&gt;Register Here&lt;/a&gt;
  </code></pre>
  
  <p>The following represents the code for my modal dialog:</p>
  
  <pre><code>&lt;div class="modal fade" id="registermodal" role="dialog" style="overflow: scroll;"&gt;
              &lt;div class="modal-dialog"&gt;
                  &lt;div class="modal-content"&gt;
                      &lt;form class="form-horizontal" name="f2" id="regisform" method="post" onsubmit="return false;" role="form"&gt;
                          &lt;div class="modal-header"&gt;
                              &lt;h4&gt;Registration&lt;button class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;&lt;/h4&gt;
                          &lt;/div&gt;
                          &lt;div class="modal-body"&gt; 
                  &lt;div class="form-group"&gt;
                                  &lt;label for="inputusername3" class="col-sm-2 control-label"&gt;Username&lt;/label&gt;
                                  &lt;div class="col-lg-8"&gt;
                                      &lt;input type="text" name="txtusername" class="form-control" id="inputusername3" placeholder="username"&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="modal-footer"&gt;   
                                  &lt;input type="submit" name="submit" id="regisBtn" class="btn btn-primary" value="Registration"&gt;
                              &lt;a class="btn btn-default" data-dismiss="modal"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
  &lt;/form&gt;
                  &lt;/div&gt; 
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>The below represent the JavaScript Code:</p>
  
  <pre><code>$(document).ready(function(){
                      $("#regisBtn").click(function(){
  var username1=$("#inputusername3").val();
  $.post("registercheck.php", {username:username1}, function(result){
  if(result==='true')
  alert("true");
  else
  alert("false");
  });
  });
  });
  </code></pre>
  
  <p>The below represent my php code:</p>
  
  <pre><code>&lt;?php
  $username1=$_POST['username'];
  $con= mysql_connect("localhost","root","");
  mysql_select_db("onlineshop",$con);
  $query1= mysql_query("select username from users where username=$username1",$con);
  if(mysql_num_rows($query1)==1){
      echo 'false';
  }else{
  mysql_query("insert into users(username)values ('".$username1."')",$con);
      session_start();
      $_SESSION['username']=$username1;
      echo 'true';
  }
  </code></pre>
  
  <p>There is error in mysqli_num_rows() shows that it expects parameter 1 to be resource, Boolean given in something like that
  I dont knw why my code is not working. please help me with my code to check whether the username is exists or not?</p>