Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.