2012-08-08 91 views
0

在一些網站的模塊,我有一個代碼Drupal的模塊MySQL錯誤

function q_cart_add($node) { 
    global $user; 
    //drupal_set_title('Добавление товара в корзину'); 
    drupal_set_title('Товар добавлен в корзину'); 
    if (!user_access('add to cart')) 
     return '<p>У вас не достаточно прав для добавления в корзину</p>'; 
    if ($node -> type != 'kartochka') 
     return '<p>В корзину можно положить только товар</p>'; 
    $added = false; 
    if ($user -> uid) { 
     $added = db_result(db_query('SELECT `added` FROM {q_cart} WHERE `uid` = %d, `nid` = %d', $user -> uid, $node -> nid)); 
     if (!$added) { 
      db_query('INSERT INTO {q_cart} (`uid`, `nid`, `added`) VALUES (%d, %d, %d)', $user -> uid, $node -> nid, time()); 
     } 
    } else { 
     foreach (isset($_COOKIE['q_cart']) && ($cart = json_decode($_COOKIE['q_cart'])) ? $cart : array() as $item) 
      if ($item -> nid == $node -> nid) { 
       $added = true; 
       break; 

但在管理面板報告在Drupal(6)我有錯誤:

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 &#039; `nid` = 806&#039; at line 1 query: 
SELECT `added` FROM q_cart WHERE `uid` = 1, `nid` = 806 in file... 

哪些錯誤,此代碼?

+0

'''是一個問題......它缺乏條件 – Julien 2012-08-08 07:23:03

+0

的引號可以這是因爲使用'123'而不是'123'? (行情) – Avdept 2012-08-08 07:32:36

回答

0

的問題是第一次查詢的這個部分:

WHERE `uid` = %d, `nid` = %d 

條件需要由ANDOR分開:

SELECT `added` FROM {q_cart} WHERE `uid` = %d AND `nid` = %d 
+0

你能告訴我哪種情況需要嗎?我沒有訪問更多的代碼,只有這個文件,但我不能說'或'或'和'應該在那裏 – Avdept 2012-08-08 11:30:08

+0

很明顯,我只是猜測,但我不認爲'OR'在這種情況下會有意義。我想你試圖根據它的節點ID和當前用戶ID來獲得產品的添加到購物車的時間(或者可能是數量)。如果這是真的,我會建議它應該是'AND' – Clive 2012-08-08 11:32:21

+0

謝謝,同樣的想法,只是想確定一下,以避免更多的錯誤 – Avdept 2012-08-08 11:45:43