title: Admin and User log in from two different tables
body: <p>I was wondering if anyone could help me - I have successfully created a log in system allowing a user (student) to log in. My system also requires an admin log in, with the admin having privileges to view pages that the student does not. Both the admin and student information comes from two different tables. Below is the code I have used for the student log in (there are two different pages - users and login). I am stuck as to how to implement the admin log in. Any help is appreciated! 
  (Admin will log in using 'adminnum' and 'adminpassword'.</p>
  
  <p><em><strong>login.php</em></strong></p>
  
  <pre><code>&lt;?php
  
  include "core/init.php";
  include "includes/content.php";
  
  if (empty($_POST) === false) {
  $studentemail = $_POST ['studentemail'];
  $studentpassword = $_POST ['studentpassword'];
  
  if (empty($studentemail) === true || empty($studentpassword) === true) {
      $errors[] = "You need to enter an email address and password"; 
  } else if (user_exists($studentemail) === false) {
      $errors[] = "We can't find that email address. Have you registered?";
  } else {
  
      if (strlen($studentpassword) &gt; 32) {
          $errors[] = 'Password too long';
          }
  
      $login = login($studentemail, $studentpassword);
      if ($login === false) {
          $errors[] = 'That email/password combination is incorrect';
      } else {
          $_SESSION['studentid'] = $login;
          header('Location: index.php');
          exit();
      }
  }
  } else {
  $errors[] = 'No data received';
  }
  include "includes/overall/overall_header.php";
  if (empty($errors) === false) {
  ?&gt;
  &lt;h2&gt; We tried to log you in, but...&lt;/h2&gt;    
  
  &lt;?php
  echo output_errors($errors);
  }
  ?&gt;
      &lt;center&gt;&lt;input id="submit" type="submit" value="Back" onclick="location.href='Login2.php'"&gt;&lt;/center&gt;
  &lt;?php
  include "includes/overall/overall_footerloggedout.php";
  ?&gt;
  </code></pre>
  
  <p><em><strong>users.php</em></strong></p>
  
  <pre><code>&lt;?php
  function logged_in() {
  return (isset($_SESSION['studentid'])) ? true : false;
  }
  
  function user_exists($studentemail) {
  $studentemail = sanitize($studentemail);
  $query = mysql_query("SELECT COUNT(`studentid`) FROM `student` WHERE `studentemail` 
           = '$studentemail'");
  return (mysql_result($query, 0) == 1) ? true : false;
  }
  
  function studentid_from_student ($studentemail) {
  $studentemail = sanitize($studentemail);
  return mysql_result(mysql_query("SELECT `studentid` FROM `student` WHERE      `studentemail` = '$studentemail'"), 0, 'studentid');
  }
  `function login($studentemail, $studentpassword) {
  $studentid = studentid_from_student($studentemail);
  
  $studentemail = sanitize($studentemail);
  $studentpassword = md5($studentpassword);
  
  return (mysql_result(mysql_query("SELECT COUNT(`studentid`) FROM `student` WHERE   `studentemail` = '$studentemail' AND `studentpassword` = '$studentpassword'"), 0) == 1) ?   $studentid : false;
  
  }
  ?&gt;
  </code></pre>