MySQL: does it have an issue "condition" ?

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
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

MySQL: does it have an issue "condition" ?

Post 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"???
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post 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]
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post by simonmlewis »

Fantastic.
Thank you very much.

I incorporated that into my full code and it works brilliantly.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply