title: Admin and normal user login system PHP MYSQL
body: <p>I have some code which attempts to check whether a user is an admin or normal user, and then compares it against an SQL table to determine which page opens up (admin page vs normal user page).</p>
  
  <pre><code>if (isset($_POST['submit']))
  {
      $user = $_POST['user'];
      $pass = $_POST['pass'];
      $admin = $_POST['admin'];
  
      if( $user == "" || $pass == "")
      {
          echo '&lt;div id ="errormsg"&gt;Please fill in all fields&lt;/div&gt;';
      }
  
      else 
      {
          $query = mysqli_query($dbcon, "SELECT * FROM users WHERE username = '$user'
          and password = '$pass' and admin = '$admin' ") or die ("Can't query the database");
          $count = mysqli_num_rows($query);
  
          if($count == 1) 
          {
              if ($admin == 1)
              {
                  $_SESSION['username'] = $user;
                  header("location: admin.php");
              }
              else if ($admin == 0)
              {
                  $_SESSION['username'] = $user;
                  header("location: users.php");
              }
              else
              {
                  echo '&lt;div id="errormsg"&gt;No matches, try again&lt;/div&gt;';
              }
          }
      }
  }
  </code></pre>
  
  <p>There are no errors, however the admin value doesn't seem to make a difference and by default opens <code>'users.php'</code> everytime. The $admin is a checkbox with value '1' when checked, the logic being to check this value against the database. Can anyone help solve this issue?</p>
  
  <p>This is the html form:</p>
  
  <pre><code>&lt;form action="&lt;?=$_SERVER['PHP_SELF']?&gt;" method="post"&gt;
    &lt;fieldset&gt;
      &lt;label class="login"&gt;Username:&lt;/label&gt;&lt;input type="text" name="user" /&gt;&lt;br /&gt;
      &lt;label class="login"&gt;Password:&lt;/label&gt;&lt;input type="password" name="pass" /&gt;&lt;br /&gt;
      &lt;label class="login"&gt;Admin?:&lt;/label&gt;&lt;input type="checkbox" value="1" name="admin" /&gt;&lt;br/&gt;
  
      &lt;input type="submit" name="submit" value="Login" /&gt;
    &lt;/fieldset&gt;
  &lt;/form
  </code></pre>