16

I used this query to insert all my values into this database:

INSERT INTO products ($fields) VALUES ($values)

However, I try to use the same format for UPDATE:

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

...and am getting thrown a syntax error:

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 '('product,make,model,' at line 1

I can't figure it out. Would appreciate any help. Thanks.

1
  • 1
    The MySQL documentation is very useful: UPDATE Syntax Commented Jul 20, 2011 at 16:41

3 Answers 3

32

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I basically ended up using this, just disappointed that I had to do it 23 times (amount of fields)
2
INSERT INTO products ($fields) VALUES ($values) ON DUPLICATE KEY UPDATE field = VALUES(field), ...

Don't forgot about unique or primary key

Comments

-5

you need an =

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

1 Comment

This is not valid MySQL syntax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.