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!

Link to comment
Share on other sites

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 `

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.