我有語法錯誤,我的代碼INSERT ... WHERE NOT EXISTS錯誤
$insert = @mysql_query("INSERT INTO topics (t_title, t_desc, t_pic, t_link, t_date,cat_id)
SELECT '$t_title','$t_desc','$t_pic','$t_link','$t_date','$cat_id'
WHERE NOT EXISTS (SELECT t_link
FROM topics
WHERE t_link = $t_link
)
")or die(mysql_error());
這將返回一個錯誤:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE NOT EXISTS (SELECT t_link FROM topics WHERE t_link = 'showthread.php?t=120' at line 3
我認爲這個問題是t_link = $ t_link
但是,當我用正常值替換它時,問題仍然存在。
任何幫助?
應該'WHERE t_link = $ t_link'不'WHERE t_link =「$ t_link''? – dunc
@dunc我試過但沒有工作。 –
請更改:die(mysql_error());通過die(echo($ insert));併發布乾淨的SQL查詢。 – danihp