2016-04-26 34 views
0

即時通訊嘗試寫一個非常(所謂)簡單的代碼將數據放入我的數據庫。在我的SQL語法錯誤不會允許插入表

$sql = "INSERT INTO `clubevent` (clubevent_id ,club_id ,event_id ,theme_id ,clubevent_date ,clubevent_start_time ,clubevent_finish_time ,clubevent_cost) VALUES (NULL , $clubstate, $eventstate, $themestate, $datestate, $sTimestate, $fTimestate, $coststate)"; 

但我不斷收到一條消息

Error: INSERT INTO clubevent (clubevent_id ,club_id ,event_id ,theme_id ,clubevent_date ,clubevent_start_time ,clubevent_finish_time ,clubevent_cost) VALUES (NULL , 4, 14, 2, 2016-04-26, 23:00:00, 05:00:00, 05) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':00:00, 05:00:00, 05)' at line 1

數據IM試圖擠進這個是:

4, 14, 2, 2016-04-26, 23:00:00, 05:00:00, 05

有誰能夠闡明這個問題一些輕?

+1

您有引文錯誤。使用準備好的聲明,你不會有這個問題。 –

+0

我同意,使用準備好的聲明來解決。這就是說,你有問題的原因是因爲你的日期/時間沒有逃脫。它讀取分號作爲break,導致錯誤 – Doug

+0

如果這是sql server,爲什麼你要將標記爲mysql? – e4c5

回答

-1
$sql = "INSERT INTO clubevent (clubevent_id ,club_id ,event_id ,theme_id ,clubevent_date ,clubevent_start_time ,clubevent_finish_time ,clubevent_cost) VALUES (NULL , ' $clubstate', '$eventstate', '$themestate', '$datestate', '$sTimestate', '$fTimestate', '$coststate')"; 
+0

我現在又得到了另一個(非常相似)的錯誤。 「您的SQL語法錯誤;檢查與您的MariaDB服務器版本相對應的手冊,以找到在''clubevent_id','club_id,event_id','theme_id','clubevent_date','clubevent_st'附近使用的正確語法第1行「 –

+0

這些應該反引號(')不是單引號(') – kojow7

+0

= @ RyanLambert答案已更新 – DrkWhz24