title: Multi user login in php
body: <p>I am designing a website which have four modules Admin, branch admin, reporter, accountant where each of the respective person can login to their respective page like admin will login to the admin page and reporter will login to it's page, but the code is not working.
  When I try login to any module it login only to the admin page and does goes to the branch admin or reporter or accountant. </p>
  
  <p>This is my index.php page</p>
  
  <pre><code>&lt;?php
   include('login.php'); // Includes Login Script
   if(isset($_SESSION['login_user']))
   {
    header("Location: admin.php");
   }
   ?&gt; 
  
   &lt;!doctype html&gt;
   &lt;html&gt;
   &lt;head&gt;
   &lt;meta charset="utf-8"&gt;
   &lt;title&gt;LoginIN&lt;/title&gt;
   &lt;link href="styles/bootstrap.min.css" rel="stylesheet"&gt;
   &lt;link href="styles/signin.css" rel="stylesheet"&gt;
   &lt;/head&gt;
  
   &lt;body&gt;
   &lt;div id="wrapper"&gt;
   &lt;header id="top"&gt;
   &lt;center&gt;&lt;h1&gt;Reporter Management System&lt;/h1&gt;&lt;/center&gt;
   &lt;div class="container"&gt;
  
   &lt;form class="form-signin" role="form"  action ="" method="post"&gt;
   &lt;h2 class="form-signin-heading"&gt;Please sign in&lt;/h2&gt;
  
   &lt;input type="email" name="username" class="form-control" placeholder="Email address" required autofocus&gt;
   &lt;input type="password" name="password" class="form-control" placeholder="Password" required&gt;
   &lt;br&gt;
   &lt;div class="checkbox"&gt;
   &lt;label&gt;
   &lt;input type="checkbox" value="remember-me"&gt;Remember me
          &lt;br&gt;
   &lt;/label&gt;
   &lt;/div&gt;
   &lt;input name="submit"button class="btn btn-lg btn-primary btn-block" type="submit" value=" Sign in"&gt;
   &lt;span&gt;&lt;?php echo $error; ?&gt;&lt;/span&gt;
   &lt;br&gt;
  &lt;a href=""&gt;Forgot your password?&lt;/a&gt;       
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my login.php page</p>
  
  <pre><code>    &lt;?php
       error_reporting( E_ALL );
       ini_set('display_errors',1);
        ini_set('display_startup_errors',1);
        error_reporting(-1);
         session_start(); // Starting Session
         $error=''; // Variable To Store Error Message
         if (isset($_POST['submit'])) {
         if (empty($_POST['username']) || empty($_POST['password'])) {
        $error = "Username or Password is invalid";
      }
      else
      {
      // Define $username and $password
        $usr=$_POST['username'];
        $pwd=$_POST['password'];
       // Establishing Connection with Server by passing server_name, user_id  and password as a parameter
       $con = mysql_connect("localhost", "root1", "oec@123") or die('Error Connecting to mysql server');
       // To protect MySQL injection for Security purpose
       $username = stripslashes($usr);
       $password = stripslashes($pwd);
       $username = mysql_real_escape_string($usr);
       $password = mysql_real_escape_string($pwd);
       // Selecting Database
       $db=mysql_select_db('rms',$con);
  
      // SQL query to fetch information of registerd users and finds user match.
      $query = mysql_query("select username, password from login where  password='$pwd' AND username='$usr'", $con) or die('Error querying database');
      $rows = mysql_num_rows($query);
  
      while ($rows = mysql_fetch_array($query)) {
      $_SESSION['Sl_no']=$rows['Sl_no'];
      if ($rows ==1)
      {
  
     // Initializing Session
     header("location: admin.php"); // Redirecting To Other Page
      }
  
     elseif ($rows==2)
     {
     header("location: branchadmin.php");
     }
     elseif($rows==3)
    {
    header("location: accountant.php");
    }
    elseif($rows==4)
   {
    header("location: reporter.php");
   }
   else
   {
  
   $error = "Username or Password is invalid";
   }
   }
   mysql_close($con); // Closing Connection
   }
   }
   ?&gt;
  </code></pre>