I am trying to add data from a form on one page and send it to another. I have done this elsewhere on the first page and it adds the data. I try it again and when I echo it out on the second page I get a null value.
Session was already started at the top of the page.
Code on the first page:
<?php
if(!isset($_POST['submit'])){}
else{
$var_fname = $_SESSION['fname'] = $_POST['fname'];
$var_lname = $_SESSION['lname'] = $_POST['lname'];
$var_address = $_SESSION['address'] = $_POST['address'];
$var_city = $_SESSION['city'] = $_POST['city'];
$var_state = $_SESSION['state'] = $_POST['state'];
$var_zip = $_SESSION['zip'] = $_POST['zip'];
$var_email = $_SESSION['email'] = $_POST['email'];
};
?>
Code on the second page:
<?php
/**
* @author
* @copyright 2022
*/
session_start();
echo $var_session = json_encode($_SESSION["shopping_cart"]);
?>
<html>
<body>
<br /><br /><br />
</body>
</html>
<?php
//echo $var_email = json_encode($_SESSION["email"]);
echo $var_fname = json_encode($_SESSION["fname"]);
?>**
The second echo outputs NULL. Form I used to gather the data:
<form method="post" action='email.php'>
First name: <input type="text" name="fname"/><br />
Last name: <input type="text" name="lname"/><br />
Address: <input type="text" name="address"/><br />
City: <input type="text" name="city"/><br />
State: <input type="text" name="state" /><br />
Zip code: <input type="text" name="zip"/><br />
Email: <input type="text" name="email"/><br />
<button type="submit">Continue to checkout</button>
</form>
--output on second page:
{"Bag01":{"name":"Laptop Bag","code":"Bag01","price":"50.00","quantity":1,"image":"product-images\/laptop-bag.jpg"}}
shopping_cart|a:1:{s:5:"Bag01";a:5:{s:4:"name";s:10:"Laptop Bag";s:4:"code";s:5:"Bag01";s:5:"price";s:5:"50.00";s:8:"quantity";i:1;s:5:"image";s:29:"product-images/laptop-bag.jpg";}}