我有以下场景:
用户可以看到所有记录的条目,但希望删除一个条目。我有下面的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";
}
?>
1条答案
按热度按时间bqucvtff1#
执行查询两次。
在
$result = mysqli_query($conn, $query);
(导致你意外行为的人)和$conn->query($query) == TRUE;
只需删除$result = mysqli_query($conn, $query);
你应该不会介意的。当然你还是应该改进你的代码,但是这一行导致了你的实际问题