title: Trying to create a login for Admin/User PHP
body: <p>I'm trying to create a log in for a user and admin from the same form, redirecting them to a certain page depending on if they are an admin or a user. </p>
  
  <p>I have created a column in my db for admin and stated that admin = 1. I seem to be getting this error when entering the details for both my admin and user. </p>
  
  <blockquote>
    <p>Fatal error: Call to a member function query() on a non-object in
    ...root\CheckLogin.php on line 31</p>
  </blockquote>
  
  <p>Any help is appreciated, thanks!</p>
  
  <pre><code>&lt;?php
  session_start();
  if(!isset($_SESSION['username'])){
      // not logged in
  }
  ?&gt;
  
  &lt;?php
  
  $host="localhost"; // Host name 
  $username=""; // Mysql username 
  $password=""; // Mysql password 
  $db_name="test"; // Database name 
  $tbl_name="members"; // Table name 
  
  // Connect to server and select databse.
  mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  mysql_select_db("$db_name")or die("cannot select DB");
  
  // username and password sent from form 
  $myusername=$_POST['myusername']; 
  $mypassword=$_POST['mypassword']; 
  
  // To protect MySQL injection
  $myusername = stripslashes($myusername);
  $mypassword = stripslashes($mypassword);
  $myusername = mysql_real_escape_string($myusername);
  $mypassword = mysql_real_escape_string($mypassword);
  
  // Query
  global $dbh
  $result= $dbh-&gt;query("SELECT * FROM members WHERE username='$myusername' AND password='$mypassword';");
  
  // Mysql_num_row is counting table row
  $count = $result-&gt;rowCount();
  
  // Determine if user is "user" or "admin"
  $usertype = $dbh-&gt;query("SELECT admin FROM members WHERE username='$myusername';");
  $row = mysql_fetch_row($usertype);
  
  // If result matched $myusername and $mypassword, table row must be 1 row
  if($count==1){
  
  // Register $myusername, $mypassword and redirect to file 
  session_start();
  $_SESSION['username'] = '$username';
  $_SESSION['password'] = '$password'; 
  $_SESSION['admin'] = $row;
  
  // Redirect to appropriate page depending on user rights. Indicator 0 for user, 1 for admin.
  if ($_SESSION['admin'] == 1){
      header("location:Admin.php");
      }
  else {
      header("location:SuccessLogin.php");
      }
  $dbh = null;
  }
  else {
  echo "";
  }
  ?&gt; 
  
  &lt;html&gt;
  &lt;body&gt;
  &lt;head&gt;
  &lt;title&gt;Login&lt;/title&gt;
  &lt;link rel="stylesheet" href="style.css" /&gt;
  &lt;link rel='stylesheet' type='text/css'&gt;
  &lt;/head&gt;
  &lt;div class="lg-container"&gt;
  &lt;center&gt;&lt;i&gt;Wrong Username or Password&lt;/i&gt;&lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>