This question already has an answer here:
I'm trying to make a shoping cart in which this product() is used for displaying what is in cart but in foreach statement it shows Warning: Invalid argument supplied for foreach()
function product()
{
foreach(@$_SESSION as $name=>$value)
{
if($value>0)
{
if(substr($name,0,5) == 'cart_'){
$id= substr($name,5,(strlen($name-5)));
echo $id;
}
}
}
}
</div>
$_SESSION is not set, it's null.
EVERY time you have a foreach nest it in an if:
if (isset($anything) && is_array($anything)) {
foreach(@$anything ...) {
}
}