PHP Error Form - Leave Contents of Form on Redirect
        Posted  
        
            by 
                user1371500
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user1371500
        
        
        
        Published on 2012-05-31T03:44:56Z
        Indexed on 
            2012/05/31
            4:40 UTC
        
        
        Read the original article
        Hit count: 208
        
I have a simple login form in which if an error occurs such as wrong password, I need it to be able to remember the username which was entered. Would I Go about doing this PHP or Javascript as I am not allowed to use JQuery.
My current PHP - (Not Including the HTML Form)
<?php
//MySQl Connection
 mysql_connect("localhost", "root", "") or die(mysql_error()); 
 mysql_select_db("clubresults") or die(mysql_error()); 
//Initiates New Session - Cookie
session_start(); // Start a new session
// Get the data passed from the form
$username = $_POST['username'];
$password = md5($_POST['pass']);
// Do some basic sanitizing
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
//Performs SQL Query to retrieve Login Details from DB
$sql = "select * from admin_passwords where username = '$username' and password = '$password'";
$result = mysql_query($sql) or die ( mysql_error() );
//Assigns a Variable Count to 0
$count = 0;
//Exectues a loop to increment on Successful Login
while ($line = mysql_fetch_assoc($result)) {
     $count++;
}
//If count is equal to 1 Redirect user to the Members Page and Set Cookie
if ($count == 1) {
     $_SESSION['loggedIn'] = "true";
     header("Location: members.php"); // This is wherever you want to redirect the user to
} else {
//Else Echo that login was a failure.
die('Login Failed. <a href=login.php>Click Here to Try Again</a>');
}
?>
Any help would be appreciated. Cheers
© Stack Overflow or respective owner