Forum Moderators: coopster

Message Too Old, No Replies

simple but strange

simplest query....

         

omoutop

11:20 am on Feb 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi to all!

i get this error message:
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 'desc, score, date, user_id, flag) VALUES ('7', '8', 'sdrvdsrvdr

when i echo my query i get:
insert INTO reviews (maj_id, min_id, title, desc, score, date, user_id, flag) VALUES ('7', '8', 'sdrvdsrvdrvdrvdsrvdsrvdrv vdv v dsv d', 'ecwECWECWEWdsavdvredrsdrvdsv...d dvrdsrv <br /> d dr v<br /> drv dvd svdsrv dsrv dsrv<br /> dsr dsrvdsrvsdrvdsrvdsr', '5', '1139176800', '3', 'N')

My query in php is like:
$insert = "insert INTO reviews (maj_id, min_id, title, desc, score, date, user_id, flag) VALUES ('".$_POST['maj_cat']."', '".$_POST['min_cat']."', '".htmlspecialchars($_POST['title'])."', '".htmlspecialchars(nl2br($_POST['desc']))."', '".$_POST['score']."', '$date_posted', '$user_id', 'N')";

tables in mysql are:
CREATE TABLE `reviews` (
`review_id` mediumint(5) NOT NULL auto_increment,
`maj_id` mediumint(5) NOT NULL default '0',
`min_id` mediumint(5) NOT NULL default '0',
`title` varchar(255) NOT NULL default '',
`desc` text NOT NULL,
`score` mediumint(5) NOT NULL default '0',
`date` int(15) NOT NULL default '0',
`user_id` mediumint(5) NOT NULL default '0',
`flag` char(2) NOT NULL default 'N',
PRIMARY KEY (`review_id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

I know there is nothing wrong with it, itis a simple query, maybe i lost an ',or ", I double checked it , even in myadmin it is not dubmitted, can you see the fault cause I cant!

Thank you in advance

omoutop

11:26 am on Feb 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have changed the field 'desc' to 'description' and it worked...is there any ghost around here? NOT LOGICAL!, anyway it works now but still can not understand the 'desc' problem. :-D

Stu_Rogers

12:39 pm on Feb 6, 2006 (gmt 0)

10+ Year Member



This one caught me out once too!

DESC is a reserved word in MySQL meaning descending.

Here is a full list of words to avoid when naming your tables and fields...

[dev.mysql.com...]

[edited by: coopster at 8:51 pm (utc) on Feb. 6, 2006]
[edit reason] linked to authoritative site [/edit]

omoutop

12:54 pm on Feb 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Stu_Rogers you are so very right!

Silly of me, had the same problem a year ago with another set of characters, although I did not learn :D from my previous mistake, you know, sometimes after coding for hours it is just there, in front of your eyes along with a logical explanation, but you are so blind to see it, amazing. Thank you for giving me some light!