Query issue

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Query issue

Post 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 =/
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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"
(#10850)
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post by SirChick »

UPDATE restaurant SET TableStaffTotal = TableStaffTotal-1 WHERE OwnerID='1'
I did ^ that is the echo it gave me.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post by SirChick »

Code: Select all

OwnerID="{$_SESSION['Current_User']}"
like that?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
Post Reply