sikas
sikas

Reputation: 5523

cannot update fields in the MySQL database

I've been trying to update a field in MySQL database but I'm getting an error.

This is my Query

UPDATE tbl SET fl1="val",fl2="val", fl3="val" WHERE fl0="val val"

This is the error I received when I tried to execute the query

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 'val WHEREfl0="val val"' at line 1

I have removed the information from the query and replaced it with dummy text.

Upvotes: 0

Views: 138

Answers (4)

lampwins
lampwins

Reputation: 920

Try using single quotes, not double. ('')

UPDATE tbl SET fl1='val',fl2=val', fl3='val' WHERE fl0='val val'

You should also use the "`" in your syntax:

UPDATE `tbl` SET `fl1`='val',`fl2`=val', `fl3`='val' WHERE `fl0`='val val'

Upvotes: 1

sikas
sikas

Reputation: 5523

FOUND IT :D ... I'm having multiple queries to be executed, this is done using PHP ... The problem was in a query in the middle was like this:

UPDATE tbl SET fl1='val',fl2='val', fl3=''val WHERE fl0='val val'

THANK YOU ALL FOR YOUR SUPPORT.

Upvotes: 1

Rene Pot
Rene Pot

Reputation: 24815

Taking a look at the error, I see 2 issues

val WHEREfl0="val val"
  • first of all, WHEREfl0 should probably be WHERE fl0

  • Secondly an issue here val WHERE[..] I think you are missing " there.

val" WHERE fl0="val val"

I am guessing you fixed the query while adding dummy text because this query is correct:

UPDATE tbl SET fl1="val",fl2="val", fl3="val" WHERE fl0="val val"

Upvotes: 1

John Woo
John Woo

Reputation: 263683

how about this?

UPDATE `tbl` 
   SET `fl1` = 'val',
       `fl2` = 'val', 
       `fl3` = 'val' 
 WHERE `fl0` = 'val val'

1.) I have changed Double Quote into Apostrophe.

2.) I added backtick in case one of your columns contains a reserved word.

Upvotes: 0

Related Questions