2013-10-08 114 views
0
"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()表示语法有问题,但它可能是别的。我会发布变量,以便知道它们来自哪里。mysql查询语法错误

$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())"; 

然而,它仍然无法正常工作......

+1

它说错误是在哪里?你能发布实际的错误信息吗? – Mike

+0

*不要*在SQL查询中直接使用'$ _POST'和'$ _GET'! –

+0

尝试回显您的SQL查询,这应该可以帮助您找到语法错​​误。提示:你在'VALUES'中忘记了一些东西。 –

回答

2

你错过闭幕括号为VALUES

... NOW())"; 

还有其他问题:

  • 的参数个数是不正确
  • 因为你没有使用参数化查询与PDO您的查询很容易受到注入/ mysqli的
1

也许你列出6列,但只给数据5?并失踪关闭)。

+0

此外,为了重申其他人,请停止使用mysql_ * funcs,并且始终使用正确的func或使用预准备语句进行转义。 – AbraCadaver

1

看起来像你缺少一个右括号,只有5个插入值到6列...

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()) 

你丢失的用户名?