Hello,
I'm having a problem getting an array to accept values. I'm using php 4.1.2 on and windows nt4 platform (not my choice). In previous versions of php I had no problems creating an array and adding items to the array everytime a user clicked on the "buy" button and the page reloaded adding the product_id to the array. Now it won't work at all!!!😕
Here is the code I'm using. I also have set the array as a cookie as session variables did not seem to be working either.
<?PHP
session_start();
//checking to see if the cookie exists, if not creating the array
if(!$cart) {
$cart = array();
setCookie("cart", $cart, time()+ 7200);
}
//retrieving the product id passed into the page by clicking on the
//buy button
$product_id = $_GET['product_id']; - product id value is 9005
$total_products = count($cart);
//making the total_products var a session var
$_SESSION['total_products'] = $total_products;
if(isset($product_id)) {
$i = 1 + total_products;
$cart[$i] = $product_id;
$total_products = count($cart);
}
while(list($key, $val) = each ($cart)) {
echo "key: $key - val: $val<br>";
}
?>
When I check to see what the $cart var is:
it says it's an array, but it won't list out the key or values of the array.
When I use: echo $cart[$i] - the result is 9 not 9005 which is the product_id value.
Could somebody please help me with this before I go crazy?
Thanks,
Trish