Error with Mysql query...need help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Darkvengance
Forum Newbie
Posts: 2
Joined: Sat Feb 03, 2007 6:32 pm

Error with Mysql query...need help

Post by Darkvengance »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm working on a small CMS and so far I am just having a few errors with the "insert" query, I've changed it several times and went to many sites trying to figure out the problem....any suggestions?

Here's the error message:

[quote]Query Failed: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, path, dwls) VALUES ('tt' ,'1' ,'test' ,'PHP' ,'test file' ,'http://www.dar' at line 1[/quote]

Here is the code:

Code: Select all

if(isset($_POST['add'])){
$path=$_POST['path'];
$name=$_POST['name'];
$act=$_POST['act'];
$desc=$_POST['desc'];
$fid=$_POST['fid'];
$type=$_POST['type'];
$dwls=0;
$query="INSERT INTO dwl_files (fid, act, name, type, desc, path, dwls) VALUES ('$fid' ,'$act' ,'$name' ,'$type' ,'$desc' ,'$path' ,'$dwls')";
$final=mysql_query($query)or die('Query Failed:'.mysql_error());
header("Location: dwl.php?action=none");
}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

I think that is because type is a MySQL keyword. Wrap your field names in backticks.

Code: Select all

INSERT INTO `table` (`field1`, `field2` ...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

http://dev.mysql.com/doc/refman/5.0/en/ ... words.html

Rename your fields so they are not reserved words. :)
Darkvengance
Forum Newbie
Posts: 2
Joined: Sat Feb 03, 2007 6:32 pm

Post by Darkvengance »

ah...overlooked that, thanks!
Post Reply