Page 1 of 1

MySQL: does it have an issue "condition" ?

Posted: Thu Jan 21, 2010 11:26 am
by simonmlewis
I am trying to pass $condition=$_POST['condition']; into

Code: Select all

mysql_query("INSERT INTO products
(condition) VALUES 
('$condition')")or die(mysql_error());
I keep getting:
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 'condition) VALUES ('used')' at line 2
The start of mine file has this:
<?php
$userid=$_POST['userid'];
$catid=$_POST['catid'];
$catname=$_POST['catname'];
$subid=$_POST['subid'];
$subname=$_POST['subname'];
$title=$_POST['title'];
.................
So line 2 is $userid.
I am not using userid in this test. I have stripped it right down to enter only $condition into the 'condition' field.

The word being passed into $condition is
used
What the heck is going on?? Does MySQL or PHP have an issue with the word "condition"???

Re: MySQL: does it have an issue "condition" ?

Posted: Thu Jan 21, 2010 11:36 am
by Eran
condition is a reserved word - http://dev.mysql.com/doc/refman/5.1/en/ ... words.html
You need to escape it with backticks
[sql]INSERT INTO `products` (`condition`) ... [/sql]

Re: MySQL: does it have an issue "condition" ?

Posted: Thu Jan 21, 2010 12:01 pm
by simonmlewis
Fantastic.
Thank you very much.

I incorporated that into my full code and it works brilliantly.