Jump to content

[SOLVED] PHP/MySQL help - syntax for an INSERT statement


wigglyworm91

Recommended Posts

Whoever wants to take this on....

 

Alright, been trying at this for a while now, can't figure out what the error is looking at, I can understand it lol.

 


	//In a hidden form field, output the number of hours added, just in case the user wants to undo her actions
	echo "<form><input type=\"hidden\" value=\"$hours\" name=\"prev_hours\"></input></form>";

	//Update database data
	--> $query = "INSERT INTO `jhs_records`.`School` (ID, First, Last, Sep, Oct, Nov, Dec, Jan, Feb, Mar, Apr, May, Total) VALUES ('$ID', '$first', '$last', '$aug', '$sep', '$oct', '$nov', '$dec', '$jan', '$feb', '$mar', '$apr', '$may', '$total')"; <--

	mysql_query($query) or die(mysql_error());

 

The arrows point to the line it points out when it squawks at me. It gives me, " 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 'Dec, Jan, Feb, Mar, Apr, May, Total) VALUES ('18072', 'Michael',    "

 

All variables exist and are strings.

(obviously, 18072 and Michael are the current values of these vars.)

 

Thanks!

The starting part of the query that was printed in the error message is where mysql found something it could not understand. Dec is a reserved keyword and should not be used as a column name - http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

 

You should rename it to something else. If you do need to use a reserved keyword as a column name you must enclose it in back-ticks `

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.