2013-05-29 146 views
0

運行我的查詢,我得到一個錯誤..我的查詢如下更新查詢

$qry = "UPDATE Offer SET offer_year='$offeryear', " . 
"course_code='$coursecode', offer_list='$offerlist', " . 
"WHERE offer_id ='$offerid'"; 

我得到了錯誤寫入的

ERROR: Record could not be added 
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 offer_id ='1'' at line 1 

做了一些改變我的更新查詢我仍然得到一個錯誤..

回答

0

試試這個(你有offerlist後逗號):

$qry = "UPDATE Offer SET offer_year='$offeryear', " . 
"course_code='$coursecode', offer_list='$offerlist' " . 
"WHERE offer_id ='$offerid'"; 
+0

感謝斯蒂芬.. :) –

+0

無後顧之憂:) .. – Stephan

3

如果你嘗試檢查一個接一個,你有額外的commaWHERE條款

$qry = "UPDATE Offer SET offer_year='$offeryear', " . 
     "course_code='$coursecode', offer_list='$offerlist' ". // remove comma here 
     "WHERE offer_id ='$offerid'"; 

一點題外話之前,查詢很容易受到與SQL Injection如果變量的值(小號)來到從外部。請看下面的文章,瞭解如何防止它。通過使用PreparedStatements你可以擺脫使用單引號圍繞值。

+0

+1一如既往:P – Stephan

2

更新這樣

$qry = "UPDATE Offer 
     SET offer_year='$offeryear', 
      course_code='$coursecode', 
      offer_list='$offerlist' 
     WHERE offer_id ='$offerid'"; 

您更新查詢您已經把多餘的逗號之前WHERE條件