名称相同的多个表单数据

时间:2022-04-03 16:51:44

I have a html form multiple data with same name. like this...

我有一个同名的html表单多个数据。像这样…

HTML code

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

如何用php $_POST[]将其发送到后端进程。请帮我. .

2 个解决方案

#1


4  

Use this HTML:

使用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:

注意,这里没有type="textbox";正确的类型是文本。在PHP中,访问如下数据:

$_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

#2


5  

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:

<?php
    print_r( $_POST['asset_id'] );
    print_r( $_POST['batch_code'] );
    print_r( $_POST['description'] );
?>

#1


4  

Use this HTML:

使用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:

注意,这里没有type="textbox";正确的类型是文本。在PHP中,访问如下数据:

$_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

#2


5  

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:

<?php
    print_r( $_POST['asset_id'] );
    print_r( $_POST['batch_code'] );
    print_r( $_POST['description'] );
?>