使用mysqli_error调试mysqli查询或将其终止 [英] debug mysqli query with or die mysqli_error

查看:69
本文介绍了使用mysqli_error调试mysqli查询或将其终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道怎么了.

$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的语法很好.我想我的数据库有问题.

How can I use mysqli_error function to check the cause of error? The syntax of PHP is just fine I think. I guess it has problem with my database.

推荐答案

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

You have a problem with single quotes. You have a ' just before your $postid, but not one after. This means that the SQL query will be seeing '$postid, ' as your first variable and then being confused about the remained.

尝试将您的SQL更改为:

Try changing your SQL to read:

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

希望有帮助.

这篇关于使用mysqli_error调试mysqli查询或将其终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆