title: Creating a login page with php - Can't see where the error lies
body: <p>EDIT: ASSIGNMENT WORK. Please don't mention External Libraries or complicated procedures that deal with security issues.</p>
  
  <p>I want to implement a very basic login page that compares the users username and password with ones stored in a database (using MySql) and then redirect to another webpage that is only available to logged in users. I have looked at these two tutorials:</p>
  
  <p><a href="http://frozenade.wordpress.com/2007/11/24/how-to-create-login-page-in-php-and-mysql-with-session/" rel="nofollow">http://frozenade.wordpress.com/2007/11/24/how-to-create-login-page-in-php-and-mysql-with-session/</a></p>
  
  <p><a href="http://www.phpro.org/tutorials/Basic-Login-Authentication-with-PHP-and-MySQL.html" rel="nofollow">http://www.phpro.org/tutorials/Basic-Login-Authentication-with-PHP-and-MySQL.html</a></p>
  
  <p>and I've attempted to use both techniques. The second one kept giving me server errors, and the first one gives me the login page, and doesn't return any errors, but then when pressing the submit button, it just doesn't do anything. I've followed it practically word for word, only changing the file names and some database column names to fit with my pre-existing stuff, but to no avail. This login page has given me an almighty headache and I would really like to get this out of the way and done with now.</p>
  
  <p>LOGIN PAGE</p>
  
  <pre><code>&lt;?php
  // Inialize session
  session_start();
  
  // Check, if user is already login, then jump to secured page
  if (isset($_SESSION['username'])) {
      header('Location: RecordEvents.php');
  }
  ?&gt;
  </code></pre>
  
  <p>... skip all the unnecessary parts</p>
  
  <pre><code>&lt;h1&gt;Login&lt;/h1&gt;
  &lt;?php
      if(!empty($errorMessage)) 
      {
          echo("&lt;p&gt;There was a problem with your login:&lt;/p&gt;\n");
          echo("&lt;ul&gt;" . $errorMessage . "&lt;/ul&gt;\n");
      } 
  ?&gt;
  &lt;form action="loginscript.php" method="post"&gt;
  Username:
  &lt;input type="text" name="username" /&gt; &lt;/br&gt;
  Password:
  &lt;input type="password" name="password" /&gt; &lt;/br&gt;
  &lt;p&gt;
      &lt;!--the submit button with an altered value. once selected the validation script will run--&gt;
      &lt;input type="submit" name="login" value="Allons-y!" /&gt;
  &lt;/p&gt;
  
  &lt;/form&gt;     
  </code></pre>
  
  <p>CONFIG.INC (I tried at first naming the file .php but that made no difference.)</p>
  
  <pre><code>&lt;?php
  
  $hostname = 'localhost';
  $dbname   = 'clubresults';
  $username = 'newuser';
  $password = 'password';
  
  // Let's connect to host
  mysql_connect($hostname, $username, $password) or DIE('Connection to host is failed,     perhaps the service is down!');
  // Select the database
  mysql_select_db($dbname) or DIE('Database name is not available!');
  
  ?&gt;
  </code></pre>
  
  <p>LOGINSCRIPT.PHP</p>
  
  <pre><code>&lt;?php
  
  // Inialize session
  session_start();
  
  // Include database connection settings
  include('Inlcude\config.inc');
  
  // Retrieve username and password from database according to user's input
  $login = mysql_query("SELECT * FROM admin_passwords WHERE (Username = '" .     mysql_real_escape_string($_POST['username']) . "') and (Password = '" .     mysql_real_escape_string(md5($_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: RecordEvents.php');
  }
  else {
  // Jump to login page
  header('Location: Login.php');
  }
  
  ?&gt;
  </code></pre>
  
  <p>RECORDEVENTS.PHP</p>
  
  <pre><code>&lt;?php  
  // Inialize session
  session_start();
  
  // Check, if username session is NOT set then this page will jump to login page
  if (!isset($_SESSION['username'])) {
      header('Location: Login.php');
  }
  Include ('Include\eventscript.php'); 
  ?&gt;
  </code></pre>
  
  <p>... blah blah</p>
  
  <pre><code>&lt;?php
      if(!empty($errorMessage)) 
      {
          echo("&lt;p&gt;There was an error with your form:&lt;/p&gt;\n");
          echo("&lt;ul&gt;" . $errorMessage . "&lt;/ul&gt;\n");
      } 
  ?&gt;
  &lt;form action="RecordEvents.php" method="post"&gt;
  Name: &lt;input type="text" name="EventName" value="&lt;?php print $varEventname;?&gt;" /&gt;   &lt;/br&gt;
  Date: &lt;input type="text" name="EventDate" placeholder="yyyy-mm-dd hh:mm:ss" value="&lt;?php print $varEventdate;?&gt;" /&gt; &lt;/br&gt;
  Location: &lt;input type="text" name="Location" value="&lt;?php print $varLocation;?&gt;" /&gt; &lt;/br&gt;
  &lt;p&gt;
      &lt;!--the submit button with an altered value. once selected the validation script will run--&gt;
      &lt;input type="submit" name="formSubmit" value="Allons-y!" /&gt;
      &lt;!--the reset button to empty the form and start again--&gt;
      &lt;input type="reset" name="formReset" value="Try Again" /&gt;
  &lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>the db is called clubresults, the table i'm using is admin_passwords and the column names are: Username, Password. </p>
  
  <p>Can anyone spot the error I am obviously making?</p>