Page 1 of 1

SQL Syntax Error... but I can't find it!

Posted: Fri Jul 09, 2004 12:39 pm
by Thomas B
This is driving me completely up the wall, really it is.

I'm currently trying to code a very basic blog/content management system, and have two tables set up, one for an FAQ and one for the blog, unsurprisingly named "faq" and "blog" respectively.

The faq table has fields named 'id', 'question', 'from' and 'answer', and the blog table has 'id','date','heading' and 'entry'.

I can add entries into the blog with the following PHP/SQL (the code to get the variables does work: I tested earlier by echo-ing them before this code chunk):

Code: Select all

<?php mysql_query("INSERT INTO blog (id,date,heading,entry) VALUES('',NOW(),'$heading','$entry')"); ?>
The FAQ entries are added in a similar way (again, tested variables, and they do work):

Code: Select all

<?php mysql_query("INSERT INTO faq (id,from,question,answer) VALUES('','$from','$question','$answer')"); ?>
But when I try and add an entry to the FAQ, I get an SQL Syntax Error. Seeing as the code is almost identical to the blog entry code, I am completely confused as to how this is producing an error.

It's probably such an obvious mistake, but I have not been at this PHP malarky for long. I did search through both manuals to no avail. Can anyone help?

Posted: Fri Jul 09, 2004 12:46 pm
by kettle_drum
The code looks fine, what syntax did you use to create the database?

Posted: Fri Jul 09, 2004 2:25 pm
by markl999
'from' is a mysql reserved word. Either rename that column or backquote it in the query, `from`