我有一个网页,其中显示了一个数据库中的信息表,每个td都有一个附加递增数字的id和名称。
while ($x <= $master_rows) {
if (isset($_POST["delete".$x])) {
echo "test1".$_POST["price".$x]." ";
$master_foodlist_delete = "DELETE FROM assig2_foodlist WHERE name=".$_POST["name".$x]."";
$master_foodlist_delete_result=$mysqli->query($master_foodlist_delete);
header("Location: ./masterlist.php");
}
$x++;
}
以及页面上相应的html(通过php生成后):
<form method="POST" name="master_submit_food">
<table id="master_foodlist">
...
<tbody>
<tr><td class="col1"><input class="col1" id="name1" name="name1" value="test" readonly=""></td>
<td class="col2"><input class="col2" id="price1" name="price1" value="9.99"></td>
<td class="col3"><input class="col3" id="lazenbys1" name="lazenbys1" type="checkbox" checked=""></td>
<td class="col3"><input class="col3" id="theref1" name="theref1" type="checkbox" checked=""></td>
<td class="col3"><input class="col3" id="tradetable1" name="tradetable1" type="checkbox" checked=""></td>
<td class="col3"><input class="col3" id="thewalk1" name="thewalk1" type="checkbox" checked=""></td>
<td class="col3"><input class="col3" id="thegrove1" name="thegrove1" type="checkbox" checked=""></td>
<td class="col4"><input type="submit" class="col4" id="delete1" name="delete1" value="delete"></td></tr>
....
</tbody></table>
<input id="submit" name="submit" type="submit" class="button" value="Submit">
</form>
基本上,我想单击delete,它会获取项目的名称并将其从数据库中删除。我有一个提交按钮来编辑整个表,目前也不工作,但它在同一个窗体内,所以我认为问题可能会被链接?
1条答案
按热度按时间liwlm1x91#
循环中的重定向导致第一个删除查询中的页面更改,将此代码移到后面while: