Page 1 of 1

Query issue

Posted: Wed Nov 21, 2007 12:47 pm
by SirChick
My query keeps presenting this error:

Code: Select all

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 'WHERE OwnerID='1'' at line 1
Yet when i echo'd it.. it looked fine so i dont get why it wont work.

This my query:

Code: Select all

$Update = "UPDATE restaurant SET TableStaffTotal = TableStaffTotal-$SellTableStaff WHERE OwnerID='{$_SESSION['Current_User']}'";
$result = mysql_query($Update) or die(mysql_error());
What is wrong exactly ? Cos the OwnerID='{$_SESSION['Current_User']} I have used many times before and its only just now not allowed it =/

Posted: Wed Nov 21, 2007 1:12 pm
by Christopher
You should echo you SQL to find the problem. I suspect that $SellTableStaff is not set so you are getting "TableStaffTotal = TableStaffTotal- WHERE"

Posted: Wed Nov 21, 2007 1:46 pm
by SirChick
UPDATE restaurant SET TableStaffTotal = TableStaffTotal-1 WHERE OwnerID='1'
I did ^ that is the echo it gave me.

Posted: Wed Nov 21, 2007 2:21 pm
by pickle
The query itself looks fine. If you're quoting the query in single quotes though, the quotes around your Owner ID are going to cause problems. Wrap your query in double-quotes & it should work.

Posted: Wed Nov 21, 2007 2:32 pm
by SirChick

Code: Select all

OwnerID="{$_SESSION['Current_User']}"
like that?

Posted: Wed Nov 21, 2007 3:38 pm
by Christopher
SirChick wrote:
UPDATE restaurant SET TableStaffTotal = TableStaffTotal-1 WHERE OwnerID='1'
I did ^ that is the echo it gave me.
The the next question would be are the names of the TableStaffTotal and OwnerID correct. And perhaps you cannot do numeric operations on TableStaffTotal.