php form process - unknown input names for quantity increase / decrease
I have an onli开发者_StackOverflow社区ne store, and the page mycart.php
will display user`s purchases like this :
image - title - price per unit - quantity - total price
The product IDs and Quantities are held in $_SESSION
arrays. (Is this good ?)
So if the user want 2 pieces of one product and 3 pieces of another product:
- How to generate the
<input>
tag (<input id="product1" name="product-1647">
?) - How to iterate through that input if the attribute
name="product-1647"
is dynamic generated?
I've studied a website and they generate inputs like above.
<input type="text" id="product1" name="product-23342">
<inpyt type="text" id="product2" name="product-47385">
...
But i can't figure it out how the post-processing is done.
Any advice will be great.html
<input type="text" id="product1" name="product[23342]">
<inpyt type="text" id="product2" name="product[47385]">
php
foreach ($_POST['product'] as $prod_id => $prod_value){
if ($prod_value){
// do whatever
}
}
精彩评论