Jump to content

[SOLVED] Cannot figure out why this UPDATE statement isn't working.


suttercain

Recommended Posts

Hi everyone,

 

I've spent nearly two hours on this and am going mad. I am trying to do a basic update, which I've done millions of times, but one line of code kicks me out an error. See two slightly different scripts below. The first one works if I take out one column, the second one doesn't work if I attempt to update the column.

 

WORKS:

$sql = "UPDATE theater SET ".
"Date='".$Date."',".
"EventType='".addslashes($EventType)."',".
"City='".addslashes($City)."',".
"Venue='".addslashes($Venue)."',".
"URL='".addslashes($URL)."'".
" WHERE id=$id";

 

DOESN'T WORK

$sql = "UPDATE theater SET ".
"Date='".$Date."',".
"EventType='".addslashes($EventType)."',".
"Show='".addslashes($Show)."',". // <--This line prevents it from working...
"City='".addslashes($City)."',".
"Venue='".addslashes($Venue)."',".
"URL='".addslashes($URL)."'".
" WHERE id=$id";

 

The 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 'Show='test',City='City1',Venue='Venue1',URL='Tickets1' WHERE id=2' at line 1

 

Thanks in advance for the help.

 

 

SHOW is reserved word in MySQL

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

 

and addslashes shouldn't be used to scape data. Use mysql_real_escape_string instead.

 

Oh man.. SHOW is a reserved word.. DOH! Thanks so much... agree w/ the addslashes, this is someone else's code and I'm not going to step on their feet :)

 

Thanks again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.