Multiple form data with the same name

I have an html form of several data with the 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 a background process. please help me..

+4
source share
2 answers

Use 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="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 is no type="textbox" ; the correct type is text .
In PHP, access the data as follows:

 $_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 
+4
source

Add 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'] ); ?> 
+5
source

All Articles