简体   繁体   中英

MySQL query code syntax error in OpenCart

I don't know why I have error:

Fatal error: Uncaught Exception: 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 '* FROM mydatabase_customer SET status='0' WHERE customer_id='11'' at line 1
Error No: 1064
INSERT INTO * FROM mydatabase_customer SET status='0' WHERE customer_id='11' in /home/nedas/domains/mypage.com/public_html/opencart/system/library/db/mysqli.php:40 Stack trace: #0 /home/nedas/domains/mypage.com/public_html/opencart/system/library/db.php(45): DB\\MySQLi->query('INSERT INTO * F...') #1 /home/nedas/domains/mypage.com/public_html/opencart/catalog/controller/account/success.php(29): DB->query('INSERT INTO * F...') #2 /home/nedas/domains/mypage.com/public_html/opencart/system/engine/action.php(79): ControllerAccountSuccess->index() #3 /home/nedas/domains/mypage.com/public_html/opencart/catalog/controller/startup/router.php(25): Action->execute(Object(Registry)) #4 /home/nedas/domains/mypage.com/public_html/opencart/system/eng in /home/nedas/domains/mypage.com/public_html/opencart/system/library/db/mysqli.php on line 40

My code:

        if ($this->customer->isLogged()) {
        $status = '0';
        $id = $this->customer->getId();
        $this->db->query("INSERT INTO * FROM perkulenkijoje_customer SET status='$status' WHERE customer_id='$id'");
        echo ("Info: Insert done");
    } else {
        echo ("Info: Please log in");
    }

Please help me.

How to successfully insert to database using opencart platform?

看起来您想UPDATE不执行INSERT的数据,应该是这样的:

$this->db->query("UPDATE perkulenkijoje_customer SET status='$status' WHERE customer_id='$id'");

if you want change a value you should use update

     UPDATE perkulenkijoje_customer
     SET status='$status' WHERE customer_id='$id'

anyway you should not use php var in sql you are at risk for sqlinjection .. for this take a look at prepared statement and binding parm for you db driver

to keep opencart db structure (I mean prefix) you need to use query like this

$this->db->query("UPDATE " . DB_PREFIX . "perkulenkijoje_customer SET status = '" . (int)$status . "' WHERE customer_id = '" . (int)$id . "'");

And better if this query you move to model file and call it in controller.

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