954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MySQL Can't solve INSERT Error

I'm having trouble with a MySQL INSERT query. I've used this exact code in many places, and even in different pages on the same web server. I feel like I've tried every variation of INSERT query with no luck.

Here are a couple that I've tried so far:

$name = 	mysql_real_escape_string($_POST['name']);
$desc = 	mysql_real_escape_string($_POST['description']);
$priority = 	mysql_real_escape_string($_POST['priority']);
$due = 		mysql_real_escape_string($_POST['date_due']);
$assign =	mysql_real_escape_string($_POST['assign_id']);
$assign_to =	mysql_real_escape_string($_POST['assign_to']); 

// There are more security measures here

$write = mysql_query ( "INSERT INTO main (name,desc,priority,given,due,status,assign,assign_to) VALUES ('$name','$desc',$priority,'$date','$due','New','$assign','$assign_to') " ) or die(mysql_error());

//The above yields 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 'desc,priority,given,due,status,assign,assign_to) VALUES ('test','test',4,'05/11/' at line 1

$write = mysql_query ("INSERT INTO main SET
		name=$name,
		desc=$desc,
		priority=$priority,
		given=$date,
		due=$due,
		status='new',
		assign=$assign,
		assign_to=$assign_to") or die(mysql_error());

//The above yields 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 'desc=test, priority=4, given=05/11/11, due=12/12/12, status='new', ass' at line 3


Any help would be greatly appreciated. I've searched for hours without a solution.

VengefulWrath
Newbie Poster
11 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

you are not passing date in proper format.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

DESC is a reserved keyword in (my)sql used with ORDER BY. Don't name your fields as reserved keywords.

smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 

@Debasisdas: I have the field set up as a varchar so it's not actually saving as a date. I probably should have it that way, but I know that portion is working.

@smantscheff: This was indeed the problem. :) It's weird though that it just started rejecting the query a couple of days ago.

Thanks for your help guys. :)

VengefulWrath
Newbie Poster
11 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: