[英]debug mysqli query with or die mysqli_error
I don't know what is wrong. 我不知道怎么了
$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";
}
How can I use mysqli_error
function to check the cause of error? 如何使用
mysqli_error
函数检查错误原因? The syntax of PHP is just fine I think. 我认为PHP的语法很好。 I guess it has problem with my database.
我猜我的数据库有问题。
You have a problem with single quotes. 您对单引号有疑问。 You have a
'
just before your $postid
, but not one after. 您在
$postid
之前有一个'
,但之后没有一个。 This means that the SQL query will be seeing '$postid, '
as your first variable and then being confused about the remained. 这意味着SQL查询将看到
'$postid, '
作为您的第一个变量,然后对剩余变量感到困惑。
Try changing your SQL to read: 尝试将您的SQL更改为:
$result = $db->query("INSERT INTO post_items(`post_id`,`content`,`date`,`user_id`,`category_id`)
VALUES ('".$postid."', '".$content."', '".$date."', '".$user_id."', '".$category_id."')");
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.