I'm trying to understand session variables by trying this code. For the purpose of the test, I created 3 pages and tried to pass the session variables around. I noticed that, the session variable is not populated in the 3rd page. I have searched to see where the problem is and I'm yet to figure it out.
page1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bio Data</title>
</head>
<body>
<form action="process.php" method="post">
<label for="fst_name">
First Name
<input type="text" name="fst_name" id="fst_name">
</label>
<label for="lst_name">
Last Name
<input type="text" name="lst_name" id="lst_name">
</label>
<input name="submit" type="submit" value=" Login ">
</form>
</body>
</html>
page2
<?php
session_start();
if (isset($_POST["submit"])){
$_SESSION['fst_name'] = $_POST['fst_name'] ;
$_SESSION['lst_name' ] = $_POST['lst_name'] ;
header("location:display.php");
}else{
echo "Error";
}
page3
<?php
session_start();
echo $_SESSION['fst_name'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Biodata Display</title>
</head>
<body>
<table>
<tr>
<td><?php echo "Hello " . $_SESSION['fst_name']; ?></td>
<td><?php echo $_SESSION['lst_name']; ?></td>
</tr>
</table>
</body>
</html>