Syntax error for table

Hi all,

I added a new column to a table and now my statement does not work. The first table I started with had the columns username, com, date – in that order. Now I’ve got username, from, com, date – again in that order.

Here is the first block of code I used to process a comment into a table:


<?php
$connection = mysql_connect("server","user","pass");
$db=mysql_select_db("db", $connection);
$comment = $_POST['commentBack'];
$date = date('j F Y \\a\	\\ g:i a');
mysql_query("INSERT INTO comments (username, com, date) VALUES ('Admin', '$comment', '$date')") or die(mysql_error());
header("location:comments.php");
?>

The new code I’m using is:


<?php
session_start();
if($_POST['commentBack'] == '')
{
	header("location:comments.php");
}
else
{
$connection = mysql_connect("server","user","pass");
$db=mysql_select_db("db", $connection);
$comment = $_POST['commentBack'];
$username = $_SESSION['username'];
$date = date('j F Y \\a\	\\ g:i a');
mysql_query("INSERT INTO comments (username, from, com, date) VALUES ('Admin', '$username', '$comment', '$date')") or die(mysql_error());
header("location:comments.php");
}
?>

As you can see the notable changes being the use of sessions to get the username. ok, so with this new peice of code I get the following error:

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 'from, com, date) VALUES (‘user1’, ‘user2’, ‘testing comments’, '27 August 2010 at ’ at line 1

I can’t see for the life of me what I’m doing wrong… nothiing… as far as I can see all spellings and punctuation are correct… Any ideas?

Thank you,

puzzled

yep that worked lol. Thanks for that sillysoft been picking over every bit of it for about 4 hours :confused:

No problem. I highly suggest not using reserved words though instead of using back ticks. But that is just a suggestion/opinion.

Hmm isnt from a reserved word in mysql? Try adding the back tick to each field Example: username, from, com, date

it didn’t occur to me that from would be reserved for some reason. I changed it now so I shouldn’t get another problem with it