大家好,我有点问题,只是想知道你们中是否有人能帮我。
当涉及到MySQL和PHP时,我有点笨拙,但问题是当我试图在数据库中添加注释时,我遇到了一个错误。这是我的公共函数代码
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注释表Structures
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
指的是什么?
我想了解你试图通过这个查询实现什么:
从注释中选择*,其中target_id="{$movieid}",user_id=‘{$user_id}’AND comment="{$comment}"AND type=2
当表本身没有type
时,DB系统将如何过滤结果?
经验法则是首先尝试使用某些IDE或命令行直接在DB上执行查询,检查查询的正确性并验证数据,然后在代码中使用它!
您的数据库中没有type
列,这就是的问题
这正是它所说的——您的表没有名为"type"的列。第一个mysql_query语句包含type = '2'
作为条件。如果你删除语句的这一部分,它就会起作用-但是,我不能判断baviour是否正确,那么:-)
表中缺少"type"列。
将查询更改为这个。(我删除了type
列,因为它不存在)
INSERT INTO comments(target_id,user_id,comment,date_added) VALUES('{$movieid}','{$user_id}','{$comment}',NOW())