我读了很多文章,很快就要把它付诸实践了,但我就是不知道自己做错了什么。
这是我代码的缩短版本:
<form method="post" enctype="multipart/form-data">
<table id="box-table-a" summary="PM Summary" style='width:90%'>
<tr>
<th>Update</th>
<th style='width:20%'>PM Comments </th>
<th>PMM Recommendations</th>
</tr>
<?php
while ($row = mysqli_fetch_array($result)) {
$PMComments = $row['PMComments'];
$PMMRecommendations = $row['PMMRecommendations'];
?>
<tr>
<td><input name="update" type="submit" id="update" value="Update"></td>
<td><?= $PMComments ?><input name="PMComments" type="text" value="<?= $PMComments ?>"></td>
<td><?= $PMMRecommendations ?><value="<?= $PMMRecommendations ?>">
<select name="PMMRecommendations">
<option value="null"></option>
<option value="No Action Taken">No Action Taken</option>
</select>
</td>
</tr>
<?php
}
?>
</table>
</form>
然后,在这个下面,我有这个部分:
if (isset($_POST['update'])) {
$PMCommentsValue = $_GET["PMComments"];
$PMMRecommendationsValue = $_GET["PMRecommendations"];
printf("PMComments: %s ", $PMCommentsValue);
echo "<br>";
printf("PMRecommendations: %s ", $PMMRecommendationsValue);
?>
表格显示正确,但我很困惑,因为我认为我在做什么,正在发生什么,都是一样的。一旦我对PM Comments输入创建的文本字段进行了更改,并点击submit,我就希望将我输入的值传输到变量中
我知道下一节代码:
if (isset($_POST['update'])) {............
正在运行,因为一旦我点击submit,我就会看到下面的两个printf(),但它们是空的,这意味着我实际上并没有向它们传输任何数据。我做错了什么?
您的表单正在张贴:
<form method="post"
但是您正试图访问来自GET数组的数据:
$PMCommentsValue = $_GET["PMComments"];
$PMMRecommendationsValue = $_GET["PMRecommendations"];
使用POST数组将其更改为两者都使用,您就可以了:
$PMCommentsValue = $_POST["PMComments"];
$PMMRecommendationsValue = $_POST["PMRecommendations"];
通常,GET数组指的是URL(例如index.php?PMComments=hello"),POST数组通常是表单数据(尽管您可以有GET表单……但嘿!)