Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting this MySQL error - 'You have an error in your SQL syntax...'?

I'm getting the following MySQL 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 'SET type = 'movie', SET category = 'New', SET music = 'Pop', SET' at line 1

Heres my query:

UPDATE music_content
SET    title = 'Classic',
SET    type = 'movie',
SET    category = 'New',
SET    music = 'Pop',
SET    audience = 'Everyone'
WHERE  id = '6'

Not sure what I'm doing wrong? - all the columns and tables exist and all the data is escaped (using mysql_real_escape_string()). Furthermore I have a valid/connected MySQL connection.

MySQL Version: 5.1.41.

like image 811
newbtophp Avatar asked Jan 20 '23 20:01

newbtophp


2 Answers

The UPDATE syntax uses only one SET even when multiple columns are being updated.

So try:

UPDATE music_content 
SET title = 'Classic',
type = 'movie',
category = 'New',
music = 'Pop',
audience = 'Everyone' 
WHERE id = '6'
like image 186
codaddict Avatar answered Apr 27 '23 04:04

codaddict


You only need to have "SET" once:

UPDATE music_content SET title = 'Classic', type = 'movie', category = 'New', music = 'Pop', audience = 'Everyone' WHERE id = '6'
like image 38
JCD Avatar answered Apr 27 '23 04:04

JCD