Jump to content

[SOLVED] Shopping Cart - Update Form Logic?


AbydosGater

Recommended Posts

Hi, im currently working on a small shopping cart script.

 

I cant seem to work out the logic for a form that will allow the users to edit their cart items.

I have a form that loops through all of the items they have added to their cart and shows them with a quantity textbox for the user to change selected quantity.

 

The thing is, the user could have any amount of items listed, and each form item is named "quantity".

So when the form is submitted i only get one $_POST['quantity']; for whatever the last product in the form is.

 

I was wondering if someone could help me with the logic behind displaying a unknown number of form elements and then looping through them for processing?

Link to comment
Share on other sites

use an array like

 

<input type="text" name="quantity[MAYBE_THE_ITEM_ID_HERE]" value="10" />

 

Then in your php you can access like this:

 

foreach ( $_POST['quantity'] as $key => $val ) {

    // $key in this example would be the Item ID and $val would be the new quantity

}

Link to comment
Share on other sites

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.