具有相同名称的多个表单数据


multiple form data with same name

我有一个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="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>

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

Square Bracket []附加到您的名称:

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

在您的php:中

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

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

请注意,没有type="textbox";则正确的CCD_ 3是CCD_
在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