mysql查询语法错误

时间:2013-10-08 17:35:45

标签: php mysql

"INSERT INTO forum_topics (category_id, poster_id, poster_username, topic_title, topic_content, date) VALUES (".$category_id.", '$poster_id', '$topic_title', '$message', NOW()"; 

mysql_error()表示语法存在问题,但可能是其他问题。我要发布变量,以便你知道它们来自哪里。

$message = $_POST['topic_message'];
$topic_title = $_POST['topic_title'];  
$category_id = $_GET['id'];

修改 将其更改为

$topic_sql = "INSERT INTO forum_topics (category_id, poster_id, poster_username, topic_title, topic_content, date) VALUES (".$category_id.", '$poster_id', '$username', '$topic_title', '$message', NOW())";

然而它仍然不起作用......

3 个答案:

答案 0 :(得分:2)

您错过了VALUES的结束语:

... NOW())";

还有其他问题:

  • 参数计数不正确
  • 由于您未使用PDO / mysqli
  • 的参数化查询,因此您的查询容易受到注入攻击

答案 1 :(得分:1)

也许您列出了6列但只提供了5个数据?并且缺少关闭)。

答案 2 :(得分:1)

看起来你错过了一个右括号,只在5列中插入5个值...

INSERT INTO forum_topics (category_id, poster_id, poster_username, topic_title, topic_content, date) 
VALUES (".$category_id.", '$poster_id', '$username', '$topic_title', '$message', NOW())

您错过了用户名吗?