Jump to content

Inserting info..

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Okay.. I have very simple problem and I have no idea how to fix it..

Quote

Can not create forum: 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, cat_id) VALUES ('Uus test', 'Jälle mingi jama', '2')' at line 1

I have tried:

$

query = "INSERT INTO forums (name, desc, cat_id) VALUES ('$name', '$desc', '$cat')";

$insert = mysql_query($query);



$query = "INSERT INTO forums (name, desc, cat_id) VALUES ('".$name."', '".$desc."', '".$cat."')";

$insert = mysql_query($query);

$insert = mysql_query("INSERT INTO forums (name, desc, cat_id) VALUES ('".$name."', '".$desc."', '".$cat."')");

And other this kind of things.. :/
please help me..

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
DESC is a mysql keyword, so it is not recognizing it as a column name. If you place backticks around the column names it will fix it.

$query = "INSERT INTO `forums` (`name`, `desc`, `cat_id`) VALUES ('$name', '$desc', '$cat')";


#3
Guest_Jaan_*

Guest_Jaan_*
  • Guests
ooooh :D my bad

#4
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
hehe. If you use mysql/php long enough, you are bound to come across this issue. I remember when I first had this problem, I spent countless hours trying to debug my code until I finally realized what was wrong. That is why I always recommend everyone use backticks.

#5
Guest_Jaan_*

Guest_Jaan_*
  • Guests
dang.. so wierd mistake.. :D i have made so many things with PHP and I have used SQL for so long time.. and i didnt notice this :D lol
anyway thanks mate :)

#6
mikelbring

mikelbring

    Programmer

  • Members
  • PipPipPipPip
  • 118 posts
If you use the field name 'char' it also does the same thing. So that is another one to watch out for.

Realize the Web Web services and design.