title: Logins error using sessions in php
body: <p>I am using this script for my login system in php, while am handling the session values it is not working</p>
  
  <p>Case is when am not validating the session values in the test page which are passed from index page the login is valid and goes to the test page after successful login but when am using the session values to validate in the test page the login is not successful, after entering the credentials the page does not goes to test.php it stays only on index.php </p>
  
  <p>Can i know what is the mistake i have done ? Thanks in advance</p>
  
  <p><strong>Login Page</strong>  </p>
  
  <pre><code>&lt;?php
  require 'connection.php';
  error_reporting(0);
  $employee_id = $connection-&gt;real_escape_string($_POST['EMPLOYEE_ID']);
  $password    = $connection-&gt;real_escape_string($_POST['PASSWORD']);
  $sql         = "SELECT EMPLOYEE_ID,EMP_NAME,DESG FROM EMPLOYEELOGIN WHERE EMPLOYEE_ID='" . $employee_id . "' AND PASSWORD='" . $password . "'";
  $result      = $connection-&gt;query($sql);
  session_start();
  if ($result-&gt;num_rows == 1) {
      $row                     = $result-&gt;fetch_row();
      // print_r($row);
      $_SESSION['EMPLOYEE_ID'] = $row[0];
      $_SESSION['EMPNAME']     = $row[1];
      $_SESSION['DESG']        = $row[2];
      header('Location: test.php');
  }
  ?&gt;
  
  // The form used
  &lt;form role="form" method="post" action='index.php' class="m-t-20"&gt;
    &lt;input class="form-control" type="text" name="EMPLOYEE_ID" required="" placeholder="Username"&gt;
  
    &lt;input class="form-control" type="password" name="PASSWORD" required="" placeholder="Password"&gt;
  
    &lt;input type="submit" class="btn btn-primary" name="submit" value="Login"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Test Page</strong></p>
  
  <pre><code>&lt;?php
  session_start();
  // error_reporting(0);
  if (isset($_SESSION['EMPLOYEE_ID'])) {
      if ($_SESSION['EMP_NAME'] != 1) {
          header("Location: index.php");
      } else {
          require 'connection.php';
      }
  } else {
      header("Location: index.php");
  }
  ?&gt;
  </code></pre>
  
  <p><strong>connection.php</strong></p>
  
  <pre><code>&lt;?php
  $connection = new mysqli("localhost","root","123","testdatabase");
  if($connection-&gt;connect_error){
      die("Connection Failed&lt;br&gt;".$connection-&gt;connect_error);
  }
  ?&gt;
  </code></pre>