can't find sql error =(

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
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

can't find sql error =(

Post by psychotomus »

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 ) VALUES ( 'Test', 'testers', 'description for test' ' at line 4

anyone know where its at?

Code: Select all

$cat = $_POST['select'];
		$name = $_POST['textForumName'];
		$desc = $_POST['textForumDesc'];
		
		//get last forum order
		$result = mysql_query("SELECT forum_order FROM forums WHERE cat='$cat' ORDER BY forum_order DESC");
		$forum_info = mysql_fetch_object($result);
		
		mysql_query("INSERT INTO forums (
				cat,
				name,
				desc
				)
				VALUES (
				'$cat',
				'$name',
				'$desc'
				)") or die(mysql_error());
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

nevermind =) desc is reserved word in sql =)
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

as you've discovered you shouldn't use reserved words in your table definitions. And there is no reason not to use full words as column name such 'description'.

However if you must, you can enclose the field name in back ticks `

Code: Select all

INSERT INTO forums (cat, name, `desc`)
VALUES
('$cat','$name','$desc')
Post Reply