Page 1 of 1

Simple syntax problem

Posted: Thu Oct 09, 2008 3:13 pm
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?

Re: Simple syntax problem

Posted: Thu Oct 09, 2008 3:21 pm
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());

Re: Simple syntax problem

Posted: Thu Oct 09, 2008 3:31 pm
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.

Re: Simple syntax problem

Posted: Thu Oct 09, 2008 3:50 pm
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());
 

Re: Simple syntax problem

Posted: Thu Oct 09, 2008 3:50 pm
by papa
Try changing name on primary.

Re: Simple syntax problem

Posted: Thu Oct 09, 2008 4:01 pm
by micknc
That did it... Who knew.

Thanks for the help.

Re: Simple syntax problem

Posted: Thu Oct 09, 2008 4:14 pm
by js2007
It's because primary is a reserved word for MySQL, see http://dev.mysql.com/doc/refman/5.0/en/ ... words.html