I have two pages, A and B.
I want to echo a variable written in A inside of the page in B.
Here's the first page:
<?php session_start(); ?>
<html>
<head>
<title>Registration Form - 1 of 2</title>
</head>
<body>
<h1>Registration - Part 1 of 2</h1>
<p>Please fill in all the required information before submitting the information.</p>
<form action="registerFormTwo.php" method="post">
First Name:<input type="text" name="firstName" /><br /><?php $_SESSION['firstName'] = firstName; ?>
Last Name:<input type="text" name="lastName" /><br /><?php $_SESSION['lastName'] = lastName; ?>
Age:<input type="text" name="age" /><br /><?php $_SESSION['age'] = age; ?>
Date of Birth:<input type="text" name="dateOfBirth" /><br /><?php $_SESSION['dateOfBirth'] = dateOfBirth; ?>
<input type="submit" />
</form>
</body>
And here's the second one:
<?php session_start(); ?>
<html>
<head>
<title>Registration Form - 2 of 2</title>
</head>
<body>
<h1>Registration - Part 2 of 2</h1>
<p>Please fill in all the required information before submitting the information.</p>
<?php //wrote this in just to test that session information is saving, but it isn't.
echo $_SESSION['name']; ?>
<form action="registerFinish.php" method="post">
Nationality<input type="text" name="nationality" /><br /><?php $_SESSION['nationality'] = nationality; ?>
Profession:<input type="text" name="profession" /><br /><?php $_SESSION['profession'] = profession; ?>
<input type="submit" />
</form>
</body>
On the second page, the name variable should be echoed, but nothing shows.
Thank you for the help.
EDIT:
Here's the code on formOne and it's still not working:
<?php session_start();
if ($_POST) {
// Store our name in the session array
$_SESSION["firstName"] = $_POST["firstName"];
}
?>
<html>
<head>
<title>Registration Form - 1 of 2</title>
</head>
<body>
<h1>Registration - Part 1 of 2</h1>
<p>Please fill in all the required information before submitting the information.</p>
<form action="registerFormTwo.php" method="post">
First Name:<input type="text" name="firstName" /><br />
Last Name:<input type="text" name="lastName" /><br /><?php $_SESSION['lastName'] = lastName; ?>
Age:<input type="text" name="age" /><br /><?php $_SESSION['age'] = age; ?>
Date of Birth:<input type="text" name="dateOfBirth" /><br /><?php $_SESSION['dateOfBirth'] = dateOfBirth; ?>
<input type="submit" />
</form>
</body>
</html>