gpt4 book ai didi

php - 'type' 中的未知列 'where clause'

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

大家好,我遇到了一些问题,想知道是否有人可以帮助我。

我对 MySQL 和 PHP 有点菜鸟,但问题是当我尝试在我的数据库中添加评论时我遇到了一个错误,这里是我的公共(public)函数代码

    public function addComment($movieid, $comment, $user_id)
{
$comment = stripslashes(strip_tags($comment));
$comment = mysql_real_escape_string($comment);
$movieid = mysql_real_escape_string($movieid);
$user_id = mysql_real_escape_string($user_id);
if (!($e = mysql_query("SELECT * FROM comments WHERE target_id='{$movieid}' AND user_id='{$user_id}' AND comment='{$comment}' AND type=2"))) {
exit(mysql_error());
}
if (mysql_num_rows($e) == 0) {
if (!($e = mysql_query("INSERT INTO comments(target_id,user_id,comment,date_added,type) VALUES('{$movieid}','{$user_id}','{$comment}',NOW(),2)"))) {
exit(mysql_error());
}
}
}

这是我的MySQL评论表结构

 1  id                int(11)                       No  None    AUTO_INCREMENT   
2 movieid int(11) No None
3 user_id int(11) No None
4 target_id int(11) No None
5 comment text utf8_general_ci No None
6 date_added datetime No None

但是当我尝试添加评论时出现此错误

Unknown column 'type' in 'where clause'

谁能帮帮我

谢谢

最佳答案

您的表没有名为 type 的列。此查询将失败。您需要将列 type 添加到表中,或者需要更改查询以完全排除对 type 的引用。 type 指的是什么?

我想了解您想要通过此查询实现什么:

SELECT * FROM comments WHERE target_id='{$movieid}' AND user_id='{$user_id}' AND comment='{$comment}' AND type=2

当表本身没有 type 时,数据库系统将如何过滤结果?

经验法则是首先尝试使用一些 IDE 或命令行直接在数据库上执行查询,检查查询的正确性并验证数据,然后再在代码中使用它 !

关于php - 'type' 中的未知列 'where clause',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17876330/

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