Jump to content

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.']"';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.