Harley1979 Posted May 11, 2007 Share Posted May 11, 2007 Hello, I am quite new to php and I am in the middle of creating a simple shopping cart but having some trouble deciding on how to go about it. My intention is to have input fields next to listed items where the user can enter a quantity for desired items, and hit a submit button once rather than having submit buttons placed next to each listed item. Does anyone have any suggestions on how to perform this? Up to now my logic has been to write a variable inside my while loop that increments with every row, and attaching this to each field name to make it unique e.g. echo " <tbody> <tr> <td>".$prodRow['item']."</td> <td>".$prodRow['size']."</td> <td>£".$prodRow['price']."</td> <td><input type='text' id='qty' name='qty' maxlength='1' size='1' /></td> <input type='hidden' name='product[".$i++."]' value='".$prodRow['id']."'> </tr> </tbody>"; } It is proving quite difficult to pick up on the other side though, that's where I'm having the most trouble. Any help would be greatly appreciated P.S. I am intentionally not using any javascript on this page. Quote Link to comment https://forums.phpfreaks.com/topic/50996-solved-simple-shopping-cart-php-help/ Share on other sites More sharing options...
MadTechie Posted May 11, 2007 Share Posted May 11, 2007 What about <?php echo " <tbody> <tr> <td>{$prodRow['item']}</td> <td>{$prodRow['size']}</td> <td>£{$prodRow['price']}</td> <td><input type='text' id='qty' name='qty[{$prodRow['id']}]' maxlength='1' size='1' /></td> <input type='hidden' name='product[{$prodRow['id']}]' value='{$prodRow['item']}'> </tr> </tbody>"; ?> <?php foreach ($_POST['product'] as $K => $P) { echo "$P QTY = {$_POST['qty'][$K]}<BR>"; } ?> **UNTESTED and i'm tired! Quote Link to comment https://forums.phpfreaks.com/topic/50996-solved-simple-shopping-cart-php-help/#findComment-250937 Share on other sites More sharing options...
Harley1979 Posted May 11, 2007 Author Share Posted May 11, 2007 Wow, thats great, thanks. Not quite thoroughly working yet though... When I echo my values passed across on the next page it is simply writing "Array" for each row. Quote Link to comment https://forums.phpfreaks.com/topic/50996-solved-simple-shopping-cart-php-help/#findComment-250975 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.