For eg I have this code on the main page.
<?php
session_start();
$_SESSION['order']=array();
?>
<form name="orderform" method="post" action="e.php">
Product Catalog
<table border="1">
<tr>
<td>Product</td>
<td>Price</td>
<td>Quantity</td>
</tr>
<?
for($i=0;$i<6;$i++){
echo '<tr>';
echo '<td><input type=hidden name="product" value="'.$i.'"> Product '.$i.'</td>';
$price=rand(1,10);
echo '<td><input type=hidden name="price" value="'.$price.'">$'.$price.'</td>';
echo '<td><input type=text name="quantity"></td>';
echo '<tr>';
}
?>
</table>
<br>
<input type="submit" name="submit" value="submit">
</form>
I have a multidimensional Session array, $_SESSION['order'] and I'm trying to save this order form of 6 product items, along with its price and quantity, so it can be retrieved on the following page after POST method is actioned.
ie on e.php file
<?php
session_start();
$_SESSION['order'][] = array('product'=>$_POST['product'],
'price'=>$_POST['price'],
'quantity'=>$_POST['quantity']);
var_dump($_SESSION['order']);
if(count($_SESSION['order'])>0){
foreach($_SESSION['order'] as $order){
echo "<p>Product = ".$order['product']."</p>";
echo "<p>Price = ".$order['price']."</p>";
echo "<p>Quantity = ".$quantity['quantity']."</p>";
}
}
?>
But the result I'm getting on e.php is I only get the last item of the order page, but not the other previous five. Did I do something wrong here? What are your thoughts?