Drupal模块mysql错误

时间:2012-08-08 07:16:57

标签: php drupal drupal-6

在某些网站的模块中,我有下一个代码

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...

这段代码有什么问题?

1 个答案:

答案 0 :(得分:0)

问题是第一个查询的这一部分:

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

条件需要由ANDOR分隔:

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