Simple syntax problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Simple syntax problem

Post by micknc »

I have looked at this until my eyes have bled. I just don't see what is wrong with this simple little delete:

Code: Select all

 
include "../../includes/dbconnect.php";
$id="101";
mysql_query("DELETE FROM productlocation WHERE primary = '".$id."'") or die (mysql_error());
 
 
I cut it way down to try and eliminate all the variables... The error I get is a syntax error "near 'primary = '101'' at line 1".

I have triple checked all of the table, and field names... Anybody see anything?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Simple syntax problem

Post by aceconcepts »

Try:

Code: Select all

 
include "../../includes/dbconnect.php";
$id=101; //remove quotes - numbers don't need them
mysql_query("DELETE FROM productlocation WHERE primary ='$id') or die (mysql_error());
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: Simple syntax problem

Post by micknc »

I cut down even more (after trying your example):

Code: Select all

include "../../includes/dbconnect.php";
mysql_query("DELETE FROM productlocation WHERE primary = 101") or die (mysql_error());
Same error. The syntax is right... I just don't understand.
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: Simple syntax problem

Post by micknc »

So, I changed to another field in that table and it works fine. The problem is I need to use the primary field. It is a primary key that is an auto incrementing INT... Is there a reason I can't use that in my where statement.
So just to recap... This works:

Code: Select all

mysql_query("DELETE FROM productlocation WHERE itemid = AA") or die (mysql_error());
 
This does not:

Code: Select all

mysql_query("DELETE FROM productlocation WHERE primary = 110") or die (mysql_error());
 
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Simple syntax problem

Post by papa »

Try changing name on primary.
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: Simple syntax problem

Post by micknc »

That did it... Who knew.

Thanks for the help.
js2007
Forum Newbie
Posts: 8
Joined: Thu Oct 09, 2008 9:37 am

Re: Simple syntax problem

Post by js2007 »

It's because primary is a reserved word for MySQL, see http://dev.mysql.com/doc/refman/5.0/en/ ... words.html
Post Reply