title: Validate user login php
body: <p>Quick question... I got my login page working right now so that when the user enters the correct information it will redirect them to the home page in a session. When they enter the wrong information it will just redirect them back to the login page. </p>
  
  <p>What I am trying to do, is when they type the wrong information I want it to still redirect them to the login page but I want it to say invalid login, please try again. I tried to echo that but it just refreshes the page no echo on it.. </p>
  
  <p>Login page</p>
  
  <pre><code>&lt;?php include '../../view/header.php'; ?&gt;
  &lt;div id="main"&gt;
  &lt;?php
  
  // Inialize session
  session_start();
  
  // Check, if user is already login, then jump to secured page
  if (isset($_SESSION['username'])) {
  header('Location: ../../admin');
  }
  
  ?&gt;
  
  &lt;html&gt;
  
  &lt;head&gt;
  &lt;title&gt;Login&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;h3&gt;Admin Login&lt;/h3&gt;
  
  &lt;table&gt;
  &lt;form method="POST" action="loginproc.php"&gt;
  &lt;tr&gt;&lt;td&gt;Username&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="username" size="20"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Password&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&lt;input type="password" name="password" size="20"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&lt;input type="submit" value="Login"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/form&gt;
  &lt;/table&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  &lt;/div&gt;
  &lt;?php include '../../view/footer.php'; ?&gt;
  </code></pre>
  
  <p>loginproc.php</p>
  
  <pre><code>&lt;?php
  
  // Inialize session
  session_start();
  
  // Include database connection settings
  require_once('database.php');
  
  // Retrieve username and password from database according to user's input
  $login = mysql_query("SELECT * FROM user WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string($_POST['password']) . "')");
  
  
  
  
  // Check username and password match
  if (mysql_num_rows($login) == 1) {
  // Set username session variable
  $_SESSION['username'] = $_POST['username'];
  // Jump to secured page
  header('Location: ../../admin');
  }
  else {
  // Jump to login page
  
  header('Location: index.php');
  
  }
  
  ?&gt;
  </code></pre>