Web Analytics Made Easy -
StatCounter Invalid Query.. HELP! - CodingForum

Announcement

Collapse
No announcement yet.

Invalid Query.. HELP!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Invalid Query.. HELP!

    I am using this INSERT, and i see absolutly no problem with it... i need help...

    In my script:
    PHP Code:
    mysql_query("INSERT INTO iteminf(name,desc,item_heal,image,useable,type,strength,defence) VALUES ('$name','$desc','$heal','0','$use','$type','$strength','$defence')"$db) or die("Invalid query: " mysql_error()); 
    the Output:

    Code:
    Invalid query: 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,item_heal,image,useable,type,strength,defence) VALUES ('test','Description'' at line 1

  • #2
    To debug this kind of thing you need to see the query with all the PHP variables expressed as their values. I suggest assigning the query text to a variable (i.e. $query = "INSERT...") and then echoing that variable. If you still can't see the problem then copy/paste the echoed query into an ad-hoc query and run it in there-- you'll probably find the problem that way.

    Comment


    • #3
      when i did that, i got the invalid query again, then i took off the or die() thing to see if that would work, and nothing was echoed..

      Comment


      • #4
        it may be that mysql dont likes yours table field desc because there is sorting option, try tu qoute it with ` this qoute ( not remember how it is in english)
        Free php image upload script
        Personal web developing blog

        Comment


        • #5
          What does this produce?
          PHP Code:
          $query "INSERT INTO iteminf (name,desc,item_heal,image,useable,type,strength,defence)
          VALUES ('
          $name','$desc','$heal','0','$use','$type','$strength','$defence')
          "
          ;

          echo 
          'QUERY TEXT:<br />'.$query;

          $result mysql_query($query$db);

          if (!
          $result) {
              die(
          "Invalid query: " mysql_error()); 

          Comment


          • #6
            Fumigator: i got

            Code:
            QUERY TEXT:
            INSERT INTO iteminf (name,desc,item_heal,image,useable,type,strength,defence) VALUES ('test','Description','0','0','yes','food','0','0')Invalid query: 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,item_heal,image,useable,type,strength,defence) VALUES ('test','Description' at line 1
            Kreoton: You were right, i used description, instead of desc, and it worked.

            Thanks to both of you for your help

            Comment

            Working...
            X