gpt4 book ai didi

php - 调试 mysqli 查询,否则出现 mysqli_error

转载 作者:行者123 更新时间:2023-11-30 00:45:21 26 4
gpt4 key购买 nike

我不知道出了什么问题。

$result = $db->query("INSERT INTO post_items(`post_id`,`content`,`date`,`user_id`,`category_id`) 
VALUES ('".$postid.", '".$content."', '".$date."', '".$user_id."', '".$category_id."')");
if($result) {
echo "hey";
}

如何使用mysqli_error函数检查错误原因?我认为 PHP 的语法很好。我猜我的数据库有问题。

最佳答案

单引号有问题。您的 $postid 之前有一个 ',但后面没有一个。这意味着 SQL 查询会将 '$postid, ' 视为您的第一个变量,然后对剩余的变量感到困惑。

尝试将 SQL 更改为:

$result = $db->query("INSERT INTO post_items(`post_id`,`content`,`date`,`user_id`,`category_id`) 
VALUES ('".$postid."', '".$content."', '".$date."', '".$user_id."', '".$category_id."')");

希望有帮助。

关于php - 调试 mysqli 查询,否则出现 mysqli_error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21421055/

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