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.

Recommended Answers

All 3 Replies

you are not passing date in proper format.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.