2012-12-06 65 views
1

我創建並編輯表中的一行,但是我在php中編輯mysql查詢給了我一個我找不到的錯誤。任何幫助?

創建查詢:

$query = "INSERT INTO timelines (
id, event_name, event_date, date_created, attendee_count, attendee_names, maximum_attendees, creator_id, creator_name, price, thumbnail 
) VALUES (
'{$timelineID}', '{$event_name}', '{$event_date}', '{$date_created}', '{$attendee_count}', '{$attendee_names}', '{$maximum_attendees}', '{$creator_id}', '{$creator_name}', '{$price}', '{$thumbnail}' 
)"; 

編輯查詢:

錯誤:

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 id =' at line 8

+1

我希望這些變量進行消毒並逃脫。 –

+1

你好,小[Bobby Tables](http://bobby-tables.com/)。 – Amadan

+0

爲什麼不先嚐試'或死(mysql_error())? –

回答

10

你有WHERE子句之前一個額外的逗號。只是刪除它,它會正常工作。

thumbnail = '{$thumbnail}', 
         ^here 
WHERE ... 

最後的查詢,

$query = "UPDATE timelines SET 
event_name = '{$event_name}', 
event_date = '{$event_date}', 
maximum_attendees = '{$maximum_attendees}', 
price = '{$price}', 
thumbnail = '{$thumbnail}' 
WHERE id = {$timelineID}"; 

您所查詢的是SQL INJECTION脆弱的,請閱讀下面的文章,以瞭解如何從它保護。

+1

+1閱讀我的評論= D –

+0

我試過了,現在得到一個不同的錯誤: 你的SQL語法錯誤;檢查與您的MySQL服務器版本對應的手冊,在第7行''附近使用正確的語法 –

+0

'thumbnail ='{$ thumbnail}''和 'WHERE id = {$ timelineID}之間是否有額外的空間「 '? –