I have a login form on the first page, from which I want to take the username and password and save them as session variables to take them forward from page to page.
the part of my code that does this is ;
I have been going over this for days now and I know the session variables are not working - on the next page I have
session_start ();
right at the top, but when I try to test the session variable with
print_r($_SESSION);
I get the output
array()
i.e. nothing in the session variables.
the other strange thing is that I am using the variable $username in several places in the code on the second page (as part of a welcome message and within queries to set other variables) this is working fine.
Where is it getting the information for this $username variable from if not from the session?
I am really confused by it all - if any can help I would be very grateful - thanks
the part of my code that does this is ;
Code:
if ($username && $password) // everything is OK
{ // query the database
$query = "SELECT UserId FROM tblUser
WHERE CLogIn='$username'
AND CPass=PASSWORD('$password')";
$result = @mysql_query($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
if ($row) // username and password match database records
{
// start the session, register the values and redirect
session_start();
$_SESSION['password'] = $row[1];
$_SESSION['username'] = $row[2];
$_SESSION['UserId'] = $row[0];
I have been going over this for days now and I know the session variables are not working - on the next page I have
session_start ();
right at the top, but when I try to test the session variable with
print_r($_SESSION);
I get the output
array()
i.e. nothing in the session variables.
the other strange thing is that I am using the variable $username in several places in the code on the second page (as part of a welcome message and within queries to set other variables) this is working fine.
Where is it getting the information for this $username variable from if not from the session?
I am really confused by it all - if any can help I would be very grateful - thanks