title: check if admin or not php
body: <p>I have a database table that holds a users username, password and other information as well as whether theyre and administrator or not. Its currently set to Char where A is for admin and U is for normal user.</p>
  
  <p>I have the following code which checks if a user exists:</p>
  
  <pre><code>&lt;?php
  session_start(); // Starting Session
  include_once('config.php');
  
  $error=''; // Variable To Store Error Message
  if (isset($_POST['submit'])) {
  if (empty($_POST['user']) || empty($_POST['pass'])) {
  $error = "Please complete both fields";
  }
  else
  {
  // Define $username and $password
  $user=$_POST['user'];
  $_SESSION['login_user']=$user;
  $pass=md5($_POST['pass']);
  // To protect MySQL injection for Security purpose
  $user = stripslashes($user);
  $pass = stripslashes($pass);
  $user = mysqli_real_escape_string($mysqli, $user);
  $pass = mysqli_real_escape_string($mysqli, $pass);
  // SQL query to fetch information of registered users and finds user match.
  $result = mysqli_query($mysqli, "SELECT * FROM users WHERE Username='$user' AND Password='$pass'");
  if(mysqli_num_rows($result) == 1) {
  header("Location: home.php");
  } else {
  $error = "Username or Password is invalid";
  }
  mysqli_close($mysqli); // Closing mysqlinection
  }
  }
  ?&gt;
  
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" href="style/style.css"&gt; 
  &lt;script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.min.js"&gt;&lt;/script&gt;
  &lt;title&gt;Login&lt;/title&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id = "logReg"&gt;
  &lt;span href="#" class="button" id="toggle-login"&gt;Log in&lt;/span&gt; 
  &lt;/div&gt;
  
  &lt;div id="login"&gt;
    &lt;div id="triangle"&gt;&lt;/div&gt;
    &lt;h1&gt;Log in&lt;/h1&gt;
    &lt;form action = "" id = "logregform" method = "POST"&gt;
      &lt;p id = "err"&gt; &lt;?php if(isset($error)) {echo $error;} ?&gt; &lt;/p&gt;
      &lt;input id = "logtxt" type="text" placeholder="Username" name = "user" required/&gt;
      &lt;input type="password" placeholder="Password" name = "pass" required/&gt;
      &lt;input type="submit" value="Log in" name = "submit" /&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;p id ="bklg"&gt;Dont have an account? &lt;a href="register.php"&gt;Sign up&lt;/a&gt;&lt;/p&gt; 
    &lt;/form&gt;
  &lt;/div&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>How would i check if Account_Type is A and if so direct the user to another page instead of the normal home.php page?</p>
  
  <p>EDIT:
  It works fine however the admin wont log in.
  Ive given it test username of 456 and a password of 456 when i enter them into the two textboxes nothing happens, the screen just refreshes and im back on the login page:</p>
  
  <p>new code below:</p>
  
  <pre><code>      &lt;?php
  session_start(); // Starting Session
  include_once('config.php');
  
  $error=''; // Variable To Store Error Message
  if (isset($_POST['submit'])) {
  if (empty($_POST['user']) || empty($_POST['pass'])) {
  $error = "Please complete both fields";
  }
  else
  {
  // Define $username and $password
  $user=$_POST['user'];
  $pass=md5($_POST['pass']);
  // To protect MySQL injection for Security purpose
  $user = stripslashes($user);
  $pass = stripslashes($pass);
  $user = mysqli_real_escape_string($mysqli, $user);
  $pass = mysqli_real_escape_string($mysqli, $pass);
  // SQL query to fetch information of registered users and finds user match.
  $result = mysqli_query($mysqli, "SELECT * FROM users WHERE Username='$user' AND Password='$pass'");
  if ($row = mysqli_fetch_array($result)) {
      //set the session variables
      $_SESSION['Username'] = $row['Username'];
      $_SESSION['Account_Type'] = $row['Account_Type'];
  
      if ($row['Account_Type'] === 'A')  {
          header ("location: adminHome.php");
          exit;
      } else {
          header ("location: home.php");
          exit;
      }
  } else {
      $error = "Username or Password is invalid";
  }
  mysqli_close($mysqli); // Closing mysqlinection
  }
  }
  ?&gt;
  
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" href="style/style.css"&gt; 
  &lt;script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.min.js"&gt;&lt;/script&gt;
  &lt;title&gt;Login&lt;/title&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id = "logReg"&gt;
  &lt;span href="#" class="button" id="toggle-login"&gt;Log in&lt;/span&gt; 
  &lt;/div&gt;
  
  &lt;div id="login"&gt;
    &lt;div id="triangle"&gt;&lt;/div&gt;
    &lt;h1&gt;Log in&lt;/h1&gt;
    &lt;form action = "" id = "logregform" method = "POST"&gt;
      &lt;p id = "err"&gt; &lt;?php if(isset($error)) {echo $error;} ?&gt; &lt;/p&gt;
      &lt;input id = "logtxt" type="text" placeholder="Username" name = "user" required/&gt;
      &lt;input type="password" placeholder="Password" name = "pass" required/&gt;
      &lt;input type="submit" value="Log in" name = "submit" /&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;p id ="bklg"&gt;Dont have an account? &lt;a href="register.php"&gt;Sign up&lt;/a&gt;&lt;/p&gt; 
    &lt;/form&gt;
  &lt;/div&gt;
  &lt;script&gt;
  
  $('#toggle-login').click(function(){
    $('#login').slideToggle('fast'); 
  });
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>