gpt4 book ai didi

php - 在 PHP 和 MySQL 中使用准备好的查询删除行

转载 作者:行者123 更新时间:2023-11-29 02:24:09 24 4
gpt4 key购买 nike

<分区>

这是删除 MySQL 数据库中记录的网络服务调用的一部分但是我收到一条错误消息“数据库错误。无法删除帖子!”我的代码哪里出错了。

 <?php

//load and connect to MySQL database stuff
require("config.inc.php");

//initial query
$query = 'DELETE FROM messages WHERE id =? AND receiver =?';
$query_params = array($_GET['id'], $_GET['receiver']);
//execute query
try {
$stmt = $db->prepare($query);
$result = $stmt->execute(array());

$response["success"] = 1;
$response["message"] = "Post Successfully DELETED!";
echo json_encode($response);
}

catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error. Couldn't delete post!";
die(json_encode($response));
}
?>

更新:

$stmt->execute(array()) 应替换为 $stmt->execute($query_params) 缺少参数

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