AbydosGater Posted July 13, 2009 Share Posted July 13, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/165791-solved-shopping-cart-update-form-logic/ Share on other sites More sharing options...
glenelkins Posted July 13, 2009 Share Posted July 13, 2009 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 } Quote Link to comment https://forums.phpfreaks.com/topic/165791-solved-shopping-cart-update-form-logic/#findComment-874535 Share on other sites More sharing options...
AbydosGater Posted July 13, 2009 Author Share Posted July 13, 2009 Works Perfectly. Thanks (Solved) Quote Link to comment https://forums.phpfreaks.com/topic/165791-solved-shopping-cart-update-form-logic/#findComment-874563 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.