我正在尝试使用循环从我的表单中获取数据。以下代码不起作用
HTML代码: -
<tr name="row_1" id="row_1">
<td align="center">1</td>
<td><input type="text" class="SText" contenteditable="true" value="Basic" name="SText_1" id="SText_1" /></td>
<td><input type="text" class="SAmount" contenteditable="true" value="6000.00" name="SAmount_1" id="SAmount_1" /></td>
</tr>
<tr name="row_2" id="row_2">
<td align="center">2</td>
<td><input type="text" class="SText" contenteditable="true" value="Housing" name="SText_2" id="SText_2" /></td>
<td><input type="text" class="SAmount" contenteditable="true" value="5000.00" name="SAmount_2" id="SAmount_2" /></td>
</tr>
PHP代码: -
<?php
$i=1;
while ($i<=10) {
$sText_$i = $_POST['SText_$i'];
$sAmount_$i = $_POST['SAmount_$i'];
//$sText_$i = $_POST['SText_'] . $i ; // dont work either
//$sAmount_$i = $_POST['SAmount_'] .$i;
$i++;
}
?>
答案 0 :(得分:4)
HTML代码: -
<tr name="row_1" id="row_1">
<td align="center">1</td>
<td><input type="text" class="SText" contenteditable="true" value="Basic" name="SText[]" id="SText_1" /></td>
<td><input type="text" class="SAmount" contenteditable="true" value="6000.00" name="SAmount[]" id="SAmount_1" /></td>
</tr>
<tr name="row_2" id="row_2">
<td align="center">2</td>
<td><input type="text" class="SText" contenteditable="true" value="Housing" name="SText[]" id="SText_2" /></td>
<td><input type="text" class="SAmount" contenteditable="true" value="5000.00" name="SAmount[]" id="SAmount_2" /></td>
</tr>
PHP代码: -
<?php
echo "<pre>";
print_r($_POST["SText"]);
print_r($_POST["SAmount"]);
?>