I have the sql created in a variable and I send it to the mysql database to update a field, but I get an error with the query. I was curious why I can't update the datetime field in my database. $query = "UPDATE site_games SET release = '2010-01-01 23:32:45' WHERE id = 1"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); This returns Error in query: UPDATE site_games SET release = '2010-01-01 23:32:45' WHERE id = 1. 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 'release = '2010-01-01 23:32:45' WHERE id = 1' at line 1 Anyone know how to fix this?
That doesn't work. Not usre what the problem is, id is an int(11) and release is a datetime set to be null. I wish the warnings were more descriptive ;/
release is a MySQL reserve word. It is not a good practice to use reserve words for your db name, table and column names. Apply back ticks if you want to use that $query = "UPDATE site_games SET `release` = '2010-01-01 23:32:45' WHERE id = 1"; Code (markup):
UPDATE `db_name`.`site_games` SET `release` = '2010-01-01 23:32:45' WHERE `site_games`.`id` =1 LIMIT 1 ; try that release db_name with the db name
yep I figured out it was because of the name release, thanks for your help guys. That error sucked and took me like 12 hours to figure out rep for all
Yeah it's good practice to surround table names and field names with ``. This will prevent lots of confusion when doing complex queries... But of course do what you feel comfortable with because it's only a suggestion.