title: Login error message in php
body: <p>I am new to PHP code and here I want to display an error message in login.php if the user entered incorrect userid or password.below I have written two-page code. login.php page submits the username and password to the check.php page. if username and password are correct then it redirects to the xyz.php else to the login page.  </p>
  
  <p><strong>login.php</strong> //login page</p>
  
  <pre><code>&lt;form name="login" enctype="multipart/form-data" action="checkpage.php" method="post"&gt;
              &lt;table border="0" cellpadding="0" cellspacing="0"&gt;
              &lt;tr&gt;
                  &lt;th&gt;Username&lt;/th&gt;
                  &lt;td&gt;&lt;input type="text" name="username" value="sandeep" onfocus="this.value=''" class="login-inp" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;Password&lt;/th&gt;
                  &lt;td&gt;&lt;input type="password" name="password" class="login-inp" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;&lt;/th&gt;
                  &lt;td valign="top"&gt;&lt;input type="checkbox" class="checkbox-size" id="login-check" /&gt;&lt;label for="login-check"&gt;Remember me&lt;/label&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;&lt;/th&gt;
                  &lt;td&gt;&lt;input type="submit" class="submit-login"  /&gt;&lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;td&gt;w want to display error message here..&lt;/td&gt;&lt;/tr&gt;
  
  &lt;/table&gt;&lt;/form&gt;
  </code></pre>
  
  <p><strong>checkpage.php</strong> //connection page </p>
  
  <pre><code>&lt;?php
      session_start();
      //connecting to db
      $username=$_POST['username'];
      $pwd=$_POST['password'];
      $q="select *from xyz where username='$username' AND password='$pwd'";
      $qry=mysql_query($q);
      if(mysql_num_rows($qry)&gt;0)
      {
          $_SESSION['username']=$username;
          echo "&lt;script&gt;window.open('xyz.php','_self')&lt;/script&gt;"; 
          }
          else{
  
              header("location:login.php");
  
              }
  ?&gt;
  </code></pre>
  
  <p>the above code work fine but i want to display the error message how could i display the error message. please guide me.</p>