title: Why i cannot display the error message in the login page?
body: <p>i want to display my error message in the login form by getting the result from the login.php ,here is the sample code that i have use.The first part is the index.php</p>
  
  <pre><code>&lt;?
  include("login.php");?&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Login Form in PHP with Session&lt;/title&gt;
  &lt;link href="style.css" rel="stylesheet" type="text/css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="main"&gt;
          &lt;h1&gt;Hup Seng&lt;/h1&gt;
          &lt;div id="login"&gt;
              &lt;h2&gt;Login Form&lt;/h2&gt;
              &lt;form action="login.php" method="post"&gt;
                  &lt;label&gt;UserName :&lt;/label&gt;
                  &lt;input id="name" name="username" placeholder="username" type="text" required&gt;
                  &lt;br&gt;
                  &lt;br&gt;
                  &lt;label&gt;Password :&lt;/label&gt;
                  &lt;input id="password" name="password" placeholder="**********" type="password" required&gt;
                  &lt;br&gt;
                  &lt;input name="submit" type="submit" value=" Login "&gt;
                      &lt;span&gt;&lt;?php  echo $error; ?&gt;&lt;/span&gt;
              &lt;/form&gt;
          &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the login.php i have put the error message under the else statement in order to pass the information to the login form</p>
  
  <pre><code>&lt;?php
  include("dbconfig.php");
  session_start(); // Starting Session
  $error=''; // Variable To Store Error Message
  //if (isset($_POST['submit'])) {
  if (isset($_POST['username']) || isset($_POST['password'])) {
  
      // Define $username and $password
      $username=$_POST['username'];
      $password=$_POST['password'];
      $pw = encode($password);
      $sql = "SELECT count(ID) as cid FROM tblUser WHERE UserId = '$username' and Password1 = '$pw'";
      $rs = odbc_exec($link_mssql,$sql);
      while (odbc_fetch_row($rs)) {
          $count=odbc_result($rs,"cid");
      }
      if ($count == 1) {
          $_SESSION['username']=$username; // Initializing Session
          header("location: homepage.php"); // Redirecting To Other Page
      } else {
          $error="username/passwod combination incorrect";
          header("location: index.php");
      }
      odbc_close($link_mssql); // Closing Connection
  }
  //}
  ?&gt;
  </code></pre>