im having a problem with this code,it seems simple but it doesnt give the right output.i created a session array and even f a value is already added,the foreach loop displays an error (invalid argument) heres the code
<?php
include ('db.inc');
session_start();
if($scbpid)
{
echo "scbpid = $scbpid <br/>";
if(!isset($HTTP_SESSION_VARS['cart']))
{
$HTTP_SESSION_VARS['cart']=array();
$HTTP_SESSION_VARS['total_price']='0.00';
echo "cart created<br>";
}
if(isset($HTTP_SESSION_VARS['cart'][$scbpid]))
{
$HTTP_SESSION_VARS['cart'][$scbpid]++;
echo "quantity added <br>";
}
else
{
$HTTP_SESSION_VARS['cart'][$scbpid]=1;
echo "new record added<br>";
}
printf(" quantity = %s <br>",($HTTP_SESSION_VARS['cart'][$scbpid]));
}
if ($HTTP_SESSION_VARS['cart']&&array_count_values($HTTP_SESSION_VARS['cart']))
{
echo "SCBPid are the following:";
foreach ($cart as $scbpid => $qty)
{
print_r ($scbpid);
}
}
else
{
echo "cart empty";
}
?>
an $scbpid is passed from the previous page and the first time this page is encountered,this is wat appears
scbpid = 1
cart created
new record added
quantity = 1
SCBPid are the following:
Warning: Invalid argument supplied for foreach() in C:\apachefriends\xampp\htdocs\cart.php on line 40
but when i come back to this page again thus incrementing the quantity, the foreach loop works. so i was wondering why it displays the image at first encounter
need help guys..c",) thnks