2013-07-30 145 views
-1

你好我無法更新我的MySQL表,當我使用如下SQL:問題與更新mysql數據庫列

if(isset($_POST['submitFeedback'])){ 
     $error = array(); 
     $success = array(); 
     $url = $_SERVER['HTTP_REFERER']; 
     $id = mysql_real_escape_string($_POST['ad_id']); 
     $email = mysql_real_escape_string($_GET['email']); 
     $voted = '1'; 
     if(!isset($_POST['userFeedback'])){ 
     $error[] = 'Please select some feedback'; 
     }else{ 
     if(isset($_POST['subComment'])){ 
      $comment = strtolower(mysql_real_escape_string($_POST['userFeedback'])); 
      $subComment = strtolower(mysql_real_escape_string($_POST['subComment'])); 

      $insertIntoBuyerFeedback = mysql_query("UPDATE buyer_feedback SET 
        seller_vote='$voted', seller_comment='$comment', 
        seller_sub_comment='$subComment', 
       WHERE ad_id='$id' AND buyer_email='$email'") or die(mysql_error()); 
      $success[] = 'Thank you for your feedback!'; 
     } 
     } 
    } 

我從瀏覽器

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 ad_id='5' AND buyer_email='[email protected]'' at line 1 

這使得出現以下錯誤對於我來說沒有任何意義,因爲我已經逃脫了有問題的字符串。即使是那些有問題的字符串

+3

多餘的逗號這裏:'... ller_sub_comment = '$ subComment',' –

回答

3

擺脫最後更新列(seller_sub_comment)後的額外逗號。

"UPDATE buyer_feedback 
SET seller_vote='$voted',seller_comment='$comment',seller_sub_comment='$subComment' 
WHERE ad_id='$id' AND buyer_email='$email'" 
+0

順便說一句,我建議你使用'$評論= mysql_real_escape_string(用strtolower($ _ POST [ 'userFeedback'])) ;'而不是'$ comment = strtolower(mysql_real_escape_string($ _ POST ['userFeedback']));'以防萬一。 – Muc

+0

爲什麼這應該有所作爲? – samayo

+0

哈哈,我發誓我試過了 – NSaid