Posting An Arbitrary Number Of Records From An Html Form
I'm making a web page in which I have a list of products, along with a field next to each product in which a customer is meant to enter the quantity they want to order. The list of
Solution 1:
You can create form fields with array notation, for example:
<inputtype="text" name="quantity[productid]">
So you could dynamically generate some fields in your form like this:
<inputtype="text" name="quantity[3]">
<inputtype="text" name="quantity[4]">
<inputtype="text" name="quantity[2]">
And then in PHP it will become an array you can loop over easily:
foreach ($_POST['quantity'] as$productId => $quantity) {
echo (int) $productId . ':' . (int) $quantity;
//etc.
}
Post a Comment for "Posting An Arbitrary Number Of Records From An Html Form"