I have a html form multiple data with same name. like this...
HTML code
<tr>
<td valign="top"><input id="" type="text" name="asset_id" size="15"/></td>
<td valign="top"><input id="" type="text" name="batch_code" size="15"/></td>
<td valign="top"><input id="" type="text" name="description" size="50"/></td>
</tr>
<tr>
<td valign="top"><input id="" type="textbox" name="asset_id" size="15"/></td>
<td valign="top"><input id="" type="textbox" name="batch_code" size="15"/></td>
<td valign="top"><input id="" type="textbox" name="description" size="50"/></td>
</tr>
how to send this in php $_POST[] to back-end process. please help me..
Append Square Bracket []
to your names:
<tr>
<td valign="top"><input id="" type="text" name="asset_id[]" size="15"/></td>
<td valign="top"><input id="" type="text" name="batch_code[]" size="15"/></td>
<td valign="top"><input id="" type="text" name="description[]" size="50"/></td>
</tr>
<tr>
<td valign="top"><input id="" type="textbox" name="asset_id[]" size="15"/></td>
<td valign="top"><input id="" type="textbox" name="batch_code[]" size="15"/></td>
<td valign="top"><input id="" type="textbox" name="description[]" size="50"/></td>
</tr>
in your php:
<?php
print_r( $_POST['asset_id'] );
print_r( $_POST['batch_code'] );
print_r( $_POST['description'] );
?>
Use this HTML:
<tr>
<td valign="top"><input id="" type="text" name="asset_id[]" size="15"/></td>
<td valign="top"><input id="" type="text" name="batch_code[]" size="15"/></td>
<td valign="top"><input id="" type="text" name="description[]" size="50"/></td>
</tr>
<tr>
<td valign="top"><input id="" type="text" name="asset_id[]" size="15"/></td>
<td valign="top"><input id="" type="text" name="batch_code[]" size="15"/></td>
<td valign="top"><input id="" type="text" name="description[]" size="50"/></td>
</tr>
Note that there's no type="textbox"
; the correct type
is text
.
In PHP, access the data like this:
$_POST["asset_id"]; // this is an array of the values of the asset_id textboxes
$_POST["batch_code"]; // array of batch codes
$_POST["description"]; // array of descriptions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With