MYSQL Updating multiple columns using variables MYSQL Updating multiple columns using variables php php

MYSQL Updating multiple columns using variables


UPDATE syntax is different than INSERT syntax. An example of UPDATE would be:

"UPDATE products SET field1 = 'value1', field2 = '$val2', field3 = 5 WHERE sku = '$checksku'"  

Though this may be insecure. You should look into parameterized queries.


INSERT INTO products ($fields) VALUES ($values) ON DUPLICATE KEY UPDATE field = VALUES(field), ...

Don't forgot about unique or primary key


you need an =

UPDATE products SET ($fields) = $values WHERE sku = '$checksku'