title: This basic login form is not doing anything
body: <p>I have edited the code from the answers so far but I am getting these errors</p>
  <blockquote>
  <p>Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Test\index.php on line 18</p>
  <p>Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Test\index.php on line 28</p>
  </blockquote>
  <p>Line 18 -  <code>$checkuser= mysqli_num_rows($query);</code></p>
  <p>Line 28 -   <code>while ($row = mysqli_fetch_array($query)) {</code></p>
  <pre><code> &lt;?php
  
  
  
  require_once('config.php');  
  
  
  if(isset($_POST['Login']) &amp;&amp; isset($_POST['uname']) &amp;&amp; isset($_POST['pass1'])) {
  // Here check if all input are sent 
  
  $uname = $sql-&gt; real_escape_string($_POST['uname']);
  $pass1 = $sql-&gt; real_escape_string($_POST['pass1']);
  
  
   if ( !empty($uname) &amp;&amp; !empty($pass1)) {
    // Check if you input are not empty
  
    $query= mysqli_query($sql, &quot;SELECT uname, pass1 FROM login WHERE uname='$uname'&quot;);
    $checkuser= mysqli_num_rows($query);
  
  
    if($checkuser != 1) {
  
  
     $error = &quot;Username doesn't exist in our database!&quot;;
    }
  
    // Change $login with $query
    while ($row = mysqli_fetch_array($query)) {
     $checkpass= $row['pass1'];
      
  
     // here i changed $pass1 to $checkpass
     if ($pass1 == $checkpass) {
  
  
      setcookie(&quot;user&quot;, $uname, time()+7200);
      $_SESSION['user'] = $uname;
      $_SESSION['start'] = time();
      $_SESSION['expire'] = $_SESSION['start'] + (60 * 60 * 60);
      header(&quot;Location: main.html&quot;);
      exit();
     } else {
  
  
      $error = &quot;Incorrect password!&quot;;
     }
    }
   } else {
  
   $error = &quot;Please enter a username and password.&quot;;
   }
  }
  
  
  
  ?&gt;
  </code></pre>