#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    11
    Rep Power
    0

    MySQL Syntax Error


    What is wrong with My Query? Is giving me this error: 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 'order, description) VALUES ('nome', 0, 1000, 'Descricao')' at line 1

    The query is

    $query = "INSERT INTO categories (name, parent, order, description) VALUES ('$catname', $catparent, $catorder, '$catdesc')";

    $catparent and $catorder are integers, so I removed the quotes. BUT does not make any diference. I tryed with and without quotes in all vars. Any Help Please?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,785
    Rep Power
    348
    order is a reserved word. You need to quote it.

    Either using those dreaded backticks `order` or if you are running in ANSI mode (highly recommended anyway) using the standard compliant double quotes: "order".
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
    http://forums.devshed.com/misc.php?do=bbcode#code

    Tips on how to ask better questions:
    http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html
  4. #3
  5. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,201
    Rep Power
    4279
    a better solution is to rename the column so that it's not a reserved word, then you won't have to escape it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    11
    Rep Power
    0

    MySQL Error


    Originally Posted by r937
    a better solution is to rename the column so that it's not a reserved word, then you won't have to escape it
    That was the problem. Renamed all the columns (to give them a better name) and is working now as it was suposed.

    Thank You Guys
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,785
    Rep Power
    348
    Originally Posted by reisve
    Renamed all the columns
    Definitely the better solution.
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
    http://forums.devshed.com/misc.php?do=bbcode#code

    Tips on how to ask better questions:
    http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

IMN logo majestic logo threadwatch logo seochat tools logo