Hi all,
I'm very new to PHP and am trying to create a login page that sets a session variable to be used at the beginning of each subsequent page to check if the login was valid.
This is what I've got:
$process = $_POST['process'];
$validated = 0;
if ($process == 1) {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "select * from user where username='$username' and password='$password'";
$result = mysql_query($sql) or die(mysql_error());
$num = mysql_num_rows($result);
/*echo $num;*/
if($num <= 0 )
{
$validated = 0;
$login_result = '<br /><font color=#ff0000>Username or password incorrect, please try again.</font><br />';
}
else
$validated = 1;
session_start();
$user_id = $result[unique_id];
session_register ("id");
session_register ("validated");
$HTTP_SESSION_VARS ["id"] = $user_id;
$HTTP_SESSION_VARS ["validated"] = $validated;
session_write_close();
header("Location: console.php");
}
Without the session variable stuff in the If statement, the username and password validate beautifully and it redirects to console.php as expected.
When I add in the session variable code though, the validation stops working and it redirects to console.php regardless of what's typed into the login box.
Can anyone explain why this happens? Or is there a different way I should be going about this?
Thanks