I just made my first attempt at starting a session. I created a page that is supposed to lookup the username and password entered on a form and then take the first name of that user and both echo it and keep it as a session variable. I then created another page that should echo the first name session variable. The problem is that when I go the second page nothing is echoed. I know that I am probably creating my session incorrectly but after looking all over the place I can;t figure it out.
Code: Select all
<?PHP session_start(); ?>
<?PHP include("connection/connect.php"); ?>
<?PHP
$UserName = $_POST["UserName"];
$Password = $_POST["Password"];
$FindFirstNameQuery = "select * from tbUsers where UserName = '$UserName' and Password = '$Password'";
$GetFirstName = mysql_query($FindFirstNameQuery);
$FirstName = mysql_fetch_array($GetFirstName);
$_SESSION['FirstName'] = $FirstName['FirstName'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome to the Test Page</title>
</head>
<body>
<?PHP
echo $_SESSION['FirstName'];
?>
<br /><br />
Click <a href="test.php">here</a> to see if the session variable carries over...Code: Select all
<?PHP include("connection/connect.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?PHP
echo $_SESSION['FirstName'];
?>
</body>
</html>