Im just tried to create a shopping cart and i am going round im circles because the few major problems.
Let me explain what i am trying to do.
I want to add items to a shopping basket but i dont know how to look up the last item in that array so it can add an icreasment of 1 so every item is unique.
Heres my VERY basic script, and im not even sure im heading in the right direction!
<?php
session_start();
if (isset($POST['submit']))
{
$productid = $POST['productid'];
$itemindex = 0;
if ($itemindex < 1)
{
//creates a basket and adds an item
$session['cart']['itemid'][$itemindex] = $productid;
$itemindex++;
$session['cart']['itemid'][$itemindex];
}
else
{
//just adds item;
$itemindex++;
$session['cart']['itemid'][$itemindex] = $productid;
}
echo $session['cart']['itemid'][1];
}
?>
<FORM METHOD='post' ACTION='cart.php'>
<INPUT TYPE='text' NAME='productid' SIZE='10'>
<INPUT TYPE='submit' NAME='submit' VALUE='Add'>
Also i would like to create a loop which lists all the values the array but i not sure how to do that. I tried but it was one of those never ending ones!
I read about the foreach command but when i tried it said i didnt have an array which makes me even more confused.
Could someone who really knows their stuff show me where im going wrong a provide me with a rough example, THANKS!! 🙂