简体   繁体   中英

What's wrong with this sql code?

If I remove the line condition=\\''.$this->condition.'\\', it works.

If I let it there, the following error message appears:

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 'condition='unknown', promotional='0', website='0', quantity='1', ' at line 7

mysql_query('UPDATE products SET 
            name = \''.$this->name.'\', 
            description = \''.$this->description.'\',
            brand = \''.$this->brand.'\',
            model = \''.$this->model.'\',   
            price=\''.$this->price.'\', 
            condition=\''.$this->condition.'\', 
            promotional=\''.$this->promotional.'\', 
            website=\''.$this->website.'\', 
            quantity=\''.$this->quantity.'\',
            service=\''.$this->service.'\'  
            WHERE id = \''.$this->id.'\' '

CONDITION is a reserved mysql keyword . You must enclose it in backticks:

`condition`=\''.$this->condition.'\', 

You have to rename condition column. See Reserved MySQL keywords table

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