post - How to retrieve text fields as an array in PHP -
i have form below allows users add more input field through addmore button . question how can retrieve array in post , echo them out . can see have 2 input fields name product[] , quantity[] (more fields can added) . have value of field using a foreach loop , store in varibla $message used in mail(). have tried each loop both , each loop code below
$product = $_post['product']; $quantity = $_post['quantity']; foreach($product $value) { $message = "<html><head> <title></title> </head> <body> <table> <tr> <td>".$value.""; } foreach($quantity $value) { $message.=" </td> <td>".$value."</td> </tr> </table> </body> </html>"; }
my input form
<form id="quick_post" method="post"> <table id="input_fields"> <tr> <td><input class="orderinput" type="text" name="product[]" /></td> <td><input class="orderquan" type="text" name="quantity[]" size="1" maxlength="3" /></td> </tr> </tr> </table> <input class="more" type="button" value="addmore" name="addmore" /> // jquery script processed on click add more fields. <input class="send" type="submit" value="send" name="send" /></form>
the output first row of products printed , remaining row quantity printed or echoed. below
product name quantity aaaaaa 22 33
the problem in first foreach
loop overwriting $message
variable , last product name passed second loop.
try this
echo "<html><head><title></title></head> <body> <table>"; for($i=0 ; $i < count($product) ; $i++) { echo "<tr><td>".$product[$i]."</td>"; echo "<td>".$quantity[$i]."</td></tr>"; } echo "</table></body></html>";
Comments
Post a Comment