PDA

View Full Version : Invalid Query.. HELP!


king2k5
09-29-2006, 08:26 PM
I am using this INSERT, and i see absolutly no problem with it... i need help...

In my script:
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:

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

Fumigator
09-29-2006, 10:10 PM
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.

king2k5
09-29-2006, 10:13 PM
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..

kreoton
09-30-2006, 12:00 AM
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)

Fumigator
09-30-2006, 12:15 AM
What does this produce?

$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());
}

king2k5
09-30-2006, 01:05 AM
Fumigator: i got

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 :)