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

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
Thomas B
Forum Newbie
Posts: 3
Joined: Thu Apr 15, 2004 12:31 pm

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

Post 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?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

The code looks fine, what syntax did you use to create the database?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

'from' is a mysql reserved word. Either rename that column or backquote it in the query, `from`
Post Reply