title: How do i display login error message on the same form after checking the database
body: <p>index.php this is my index file and works fine. what is does is checks the user session variable and displays the current logged-in user.</p>
  
  <pre><code>&lt;?php
      error_reporting(E_ALL ^ E_NOTICE);
      session_start();
      $username = $_SESSION['username']; 
  ?&gt;
  
     &lt;div id="userinfo"&gt;
     &lt;?php
        if ( $username ) {
            echo "welcome &lt;b&gt;$username&lt;/b&gt; &lt;a href='logout.php'&gt;Logout&lt;/a&gt;";
        } else {
            echo 'welcome guest please &lt;a href="login.php"&gt;Login&lt;/a&gt;';
        }
     ?&gt; 
     &lt;/div&gt;
  </code></pre>
  
  <p>loginform.php</p>
  
  <pre><code>&lt;?php
      error_reporting(E_ALL ^ E_NOTICE);
      session_start();
      $username = $_SESSION['username'];
  ?&gt;
  &lt;form id='frmlogin' method="post" action="esk.php"&gt;
      &lt;div id="dialogcontainer"&gt;
          &lt;div id="dialog"&gt;
             &lt;h3&gt;Welcome to Talk Login&lt;/h3&gt;
             &lt;p&gt;Username&lt;/p&gt;
             &lt;input type="text" id="txtloginusername" name="txtloginusername"/&gt;
             &lt;p&gt;Password&lt;/p&gt;
             &lt;input type="password" id="txtloginpassword" name ="txtloginpassword"/&gt; &lt;br /&gt;&lt;br /&gt;
             &lt;button type="submit"&gt;Login&lt;/button&gt;
             &lt;br&gt;
             &lt;br&gt;
             &lt;div id="logindisplay" class ="display"&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;        
   &lt;/form&gt;
  </code></pre>
  
  <p>login.php  instead of echoing the message to some other page i want it to be display on the loginform.php which happens to be my login form. </p>
  
  <pre><code> &lt;?php
      error_reporting(E_ALL ^ E_NOTICE);
      session_start();
      $username = $_SESSION['username'];
      $user = $_POST['txtloginusername'];
      $pass = $_POST['txtloginpassword'];
  
      if ( $user ) {
          require ('connect.php');
          $query = mysql_query("SELECT * FROM user WHERE username = '$user'");
          $numrows = mysql_num_rows( $query );
          if ( $numrows == 1 ) {
             $row = mysql_fetch_assoc( $query );
             $dbpass = $row['password'];
             $dbuser = $row['username'];
             $dbactive = $row['active'];
  
             if ( $pass == $dbpass ) {
                if ( $dbactive == 1 ) {
                    $_SESSION['username'] = $dbuser;
                    header("location:index.php"); //"success";
                }
             } else {
                    echo "You did not enter the correct password"; //Display this somewhere on loginform.php
             }    
          } else {
             echo"Invalid Username"; // //Display this also in loginform.php 
          }
  
          mysql_close();
      } else {
          echo "Wrong username"; //this too;  
      } 
  
      ?&gt;
  </code></pre>