I have just started using session variables and I'm running into some problems.
I'm trying to echo out a variable from my form processing script back onto another page but currently I'm not getting any results.
Before starting let me say that I have already checked out other questions including this one:
I checked everything off that first answer list and still nothing.
The only error i am getting is:
Notice: Undefined index: id
Which I'm assuming is because when the page first starts it doesn't know what id is but even after submitting the error persists.
index.php
<?php
session_start();
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP Sessions</title>
</head>
<body>
<?php echo $_SESSION['id']; ?>
<form action="submit.php" method="post">
<input type="text" name="number" id="number">
<button type="submit">Submit</button>
</form>
</body>
</html>
submit.php
<?php
session_start();
try {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = $_POST['number'];
};
header('Location: http://home.com/');
exit();
} catch (Exception $e) {
echo $e->getMessage();
}
?>