简体   繁体   中英

how to fix an error in SQL syntax

Please help me with this error:

Notice: Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'c FROM oc_coupon c LEFT JOIN oc_cheaper_order_coupons coc using(coupon_id) WHER' at line 1 Error No: 1064 DELETE oc_coupon c FROM oc_coupon c LEFT JOIN oc_cheaper_order_coupons coc using(coupon_id) WHERE coc.order_id = '26' in /home/blablabl/public_html/shop/system/database/mysql.php on line 50

The code is:

class ModelSaleCheaper extends Model {
    public function deleteOrder($order_id) {
        $this->db->query("DELETE " . DB_PREFIX . "coupon c FROM " . DB_PREFIX . "coupon c LEFT JOIN  " . DB_PREFIX . "cheaper_order_coupons coc using(coupon_id) WHERE coc.order_id = '" . (int)$order_id . "'");
        $this->db->query("DELETE " . DB_PREFIX . "coupon_product cp FROM " . DB_PREFIX . "coupon_product cp LEFT JOIN  " . DB_PREFIX . "cheaper_order_coupons coc using(coupon_id) WHERE coc.order_id = '" . (int)$order_id . "'");
        $this->db->query("DELETE FROM " . DB_PREFIX . "cheaper_order_coupons  WHERE order_id = '" . (int)$order_id . "'");
        $this->db->query("DELETE FROM " . DB_PREFIX . "cheaper_order  WHERE order_id = '" . (int)$order_id . "'");

A valid query might look like this:

DELETE c -- assuming you only want to DELETE from coupon 
  FROM " . DB_PREFIX . "coupon c 
  JOIN " . DB_PREFIX . "cheaper_order_coupons coc USING(coupon_id) 
 WHERE coc.order_id = $order_id;

Another example...

DELETE cp 
  FROM oc_coupon_product cp 
  JOIN oc_cheaper_order_coupons coc USING(coupon_id) 
 WHERE coc.order_id = 26

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM