Jump to content

[SOLVED] SESSIONS for shopping cart


Omzy

Recommended Posts

What I'm looking to do is store multiple items in the SESSIONS array (the whole point of using sessions really).

 

The items will be POSTed to cart.php, all items include fileds "item_name", "item_code", "item_price".

 

How can I ensure the items are added uniquely to the SESSIONS array?

Link to comment
https://forums.phpfreaks.com/topic/176847-solved-sessions-for-shopping-cart/
Share on other sites

Cheers. The next thing I need to do is enable quantities to be changed. I got this to work when there is only 1 item but it doesn't seem to work when there is more than 1 item:

 

foreach($_SESSION as $value)
{
<input type="text" name="quantity_update" value="'.$value[2].'" size="2"/>
<input type="hidden" name="item_number" value="'.$value[0].'"/>
}

 

 
$_SESSION[$_POST['item_number']] = array($_POST['item_number'], $_POST['item_name'], $_POST['quantity'], $_POST['amount']);

if(isset($_POST['quantity_update']))
{
$_SESSION[$_POST['item_number']][2] = $_POST['quantity_update'];
}

 

I think I need to put it into an array or something, but how?

Ja, do sumfin like this:

$_SESSION['items'][$item_code] = bla bla bla;

 

den when you loop just do

 

foreach ($_SESSION['items'] as $k => $v) {

  // $v will hold the array for whatever itemcodes are in your item list and $k will be your item_code

}

 

and you're gonna wanna echo something like dis:

 

echo 'name="item_quantity['.$k.']"';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.