Passing arrays via sessions
Posted: Mon Oct 28, 2002 10:13 am
Hi guys,
I have the following code, which I am really struggling to understand what I have done wrong.
when I revist with a different pid all the previous array entries have been removed.
I have the following code, which I am really struggling to understand what I have done wrong.
Code: Select all
<?php
if(!session_start()){
echo "Failed when starting session";
exit;
}
//retrieve product array from session
if ( isset($_SESSIONї'products']) ) { $products = $_SESSIONї'products']; }
//retrieve variables from the request
if (isset($_REQUESTї'pid'])) { $pid = $_REQUESTї'pid']; }
$productsї] = array ("pid" => $pid, "quant" => 1);
session_register('products');
foreach ($products as $prod){
echo "Product # ".$prodї'pid']." : ".$prodї'quant']."<br />";
}
echo "<a href="./index.php">Back</A>"
?>