更新查询在opencart中不起作用

时间:2014-02-19 14:20:43

标签: php mysql opencart

请帮忙。我有以下代码:

$this->db->query("INSERT INTO " . DB_PREFIX . "competition_winners SET email_id= '" . $this->db->escape($data['email']) . "', name= '" . $this->db->escape($data['name']) . "', competition_id='" . (int)$data['competition_id'] . "'");
    $rate = $this->db->query("SELECT competition_rate FROM " . DB_PREFIX . "customer WHERE email = '" . $data['email'] . "'");
        $frate = $rate->row['competition_rate'];
        $ratefinal=$frate+1;
        $ratefinal=$frate+1;
        $sql2 = "UPDATE" . DB_PREFIX . "customer SET competition_rate = '" . (int)$ratefinal . "' WHERE email= '" .$data['email'] . "'";

        $query2 = $this->db->query($sql2);
    }

查询不会更新任何内容。我无法获得vardump因为我正在使用Opencart CMS并且目前正在使用模型。我错过了什么?

1 个答案:

答案 0 :(得分:1)

我认为你缺少tablename和update关键字之间的空格:

而不是:

$sql2 = "UPDATE" . DB_PREFIX . "customer SET competition_rate = '" . (int)$ratefinal . "' WHERE email= '" .$data['email'] . "'";

尝试

$sql2 = "UPDATE " . DB_PREFIX . "customer SET competition_rate = '" . (int)$ratefinal . "' WHERE email= '" .$data['email'] . "'";