Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple form data with same name [closed]

Tags:

html

php

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..

like image 301
Dula Avatar asked Jan 15 '23 18:01

Dula


2 Answers

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'] );
?>
like image 114
You Qi Avatar answered Jan 18 '23 08:01

You Qi


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
like image 40
Abraham Avatar answered Jan 18 '23 08:01

Abraham