gpt4 book ai didi

php - 仅在勾选复选框时运行删除 PHP/SQL

转载 作者:行者123 更新时间:2023-11-29 07:26:12 25 4
gpt4 key购买 nike

我有以下场景:

用户可以看到所有记录的条目,但想删除一个条目。我有以下 php 部分,但这会删除表中的所有内容(这很好),但不管复选框是否被选中。它应该只在复选框被选中时删除:

    // Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "DELETE FROM `trips` WHERE `id` > 1" ;
// this changes later to user specific instances - only example for now

$result = mysqli_query($conn, $query);
if(isset($_POST['deletecheck']) && $_POST['deletecheck'] == 'Yes' )
{
$conn->query($query) == TRUE;
echo "deleted";
}
else
{
echo "ERROR: tick the checkbox and press delete to delete the trip";
}

?>

最佳答案

您执行了两次查询。

$result = mysqli_query($conn, $query);(导致您意外行为的那个)和 $conn->query($query) == TRUE;

只需删除 $result = mysqli_query($conn, $query); 就可以了。

当然你应该改进你的代码,但是这一行导致了你的实际问题

关于php - 仅在勾选复选框时运行删除 PHP/SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53634476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com