Ahh yes I seen the error in my ways,
I shouldn't continue to call my itemsincart() function ..
so what I did was $_itemsincart = itemsincart();
and just used the variable instead of the function each time so the results were consistent.
PHP Code:
function addtocart() // add the product to the cart using the product id.
{
if(isset($_POST['addproductid'])) // new products waiting to be added to cart from addtocart form
{
$_itemsinarray = itemsincart();
$_SESSION['cart'][$_itemsinarray][0] = $_POST['addproductid']; // add a new product onto the end of the array
$_SESSION['cart'][$_itemsinarray][1] = $_POST['productquantity']; // quantity of new product
unset($_POST['addproductid']);
unset($_POST['productquantity']);
echo $_SESSION['cart'][$_itemsinarray][1]." * Product ".$_SESSION['cart'][$_itemsinarray][0]." added to cart";
}
}
Now it works properly!, I looked at your code examples for alternative methods. But I am too much of a newb and I am just going to continue with the way I have done it so I don't confuse myself any further.
Thanks for your suggestions and help, I can see I am going to learn a lot in these forums ..
As for you...