2013-10-08 113 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()) 

你丟失的用戶名?