[SOLVED] - Spot the SQL Syntax 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
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

[SOLVED] - Spot the SQL Syntax Error

Post by iknownothing »

Hey Guys, I have the following, and can't for the life of me, find the SQL syntax error, can anyone see it...

Code: Select all

$sql = mysql_query("INSERT INTO news_events (id, title, posted, description, is_event, when, where) VALUES ('', '$title', '$posted', '$description', '$is_event', '$when', '$where')");
		if (!$sql){
			echo mysql_error();
		}
Thanks.
Last edited by iknownothing on Wed Aug 22, 2007 3:14 pm, edited 1 time in total.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

"where" should be a reserved word and should not be used as a column name. Is the id an integer... you are saving as a string.

When posting things like this and you have an error message can you post it as well.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

btw, i would expect where to be a special value... thus it would need proper escaping
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

yeah, I could have changed its name, but that seemed to hard (lazy), so i escaped it instead.
Post Reply