I have a sample program that passes the inputs entered in the fields to a $_SESSION, then echos to a 3rd page. But it seems the inputs entered in the first page (index.php) does not echo, whereas in the 2nd page, it does. How do I fix that?
I also want to have a code that the inputs are destroyed with closed, that's why I have a onunload="<?php session_destroy(); ?>"
in every body
of my code.
index.php code:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form class="" method="post" action="page1indexHandler.php" onunload="<?php session_destroy(); ?>">
Check-in: <input type="text" name="check_in" placeholder="Check-in">
Check-out: <input type="text" name="check_out" placeholder="Check-out">
<br>
<input type="submit" name="Proceed" value="Proceed">
</form>
</body>
</html>
page1indexHandler.php code:
<?php
session_start();
$_SESSION['check_in'] = $_POST['check_in'];
$_SESSION['check_out'] = $_POST['check_out'];
header("Location: register.php");
?>
register.php (second page) code:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form class="" method="post" action="page2registerHandler.php" onunload="<?php session_destroy(); ?>">
first name: <input type="text" name="firstname">
last name : <input type="text" name="lastname">
<br>
<input type="submit" name="proceed" value="proceed">
</form>
</body>
</html>
output.php (just for echo / checking purposes) code:
<?php
session_start();
echo $_SESSION['check_in'] . "<br>";
echo $_SESSION['check_out'] . "<br>";
echo $_SESSION['firstname'] . "<br>";
echo $_SESSION['lastname'] . "<br>";
?>
Here is the output of the sample program:
Notice: Undefined index: check_in in C:\xampp\htdocs\series\kenny\output.php on line 3
Notice: Undefined index: check_out in C:\xampp\htdocs\series\kenny\output.php on line 4
John // I inputted this in the register.php code, it echoes
Doe // also this one