无法检索POST数据

时间:2018-05-27 13:53:57

标签: php html mysql

我有一个网页,显示数据库中的信息表,每个td都有id& name,附加了递增的数字。

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>

基本上,我想点击删除,它获取项目的名称并从数据库中删除它。我有一个提交按钮来编辑整个表格当前也不起作用,但它在同一个表格中,所以我认为问题可能会被链接?

1 个答案:

答案 0 :(得分:0)

循环中的重定向导致第一个DELETE查询中的页面更改,在while:

之后移动此代码
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);
    }
    $x++;
}
header("Location: ./masterlist.php");