tags:

views:

25

answers:

2

i want all fields that got a certain value to be changed to a different value.

but my code gave me an error

     UPDATE maps
     SET city_id = $new_id
     WHERE city_id = $old_id

you cant write it like that?

I get this error code:

    Couldn't execute 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 '' at line 3
+1  A: 
$query = "UPDATE maps
 SET city_id = '$new_id'
 WHERE city_id = '$old_id'";

Additional example here

gmcalab
please read my updated question
weng
Same fix just need single quotes added around each var.
gmcalab
i thought that u dont need single quotes around INT?
weng
You'd think that but you do :)
gmcalab
+1  A: 

If your IDs are integers, make sure that there's none that are null, since the command

UPDATE maps SET city_id=4 WHERE city_id=

will fail, while

UPDATE maps SET city_id='4' WHERE city_id=''

will not fail, though likely won't update anything, presuming city_id is the primary key of your table and all rows are supposed to have one, so none will have city_id equal to an empty string.

If you are still getting an error, have your script echo out the full SQL string (after variables have been replaced with values) to see if there's unusual input in your variables causing it.

MidnightLightning