Page 1 of 1

Insert problem

Posted: Mon Nov 29, 2004 8:55 am
by Archy
Why am I getting this error, I have used it hundreds of times, and am only changing the variables and the column names. This is the code that I am using:

Code: Select all

$sql = "INSERT INTO news (name, date, short, long) VALUES ('$nameU', '$timeNow', '$shortU', '$longU')";
     $rs = mysql_query($sql) or die(mysql_error());
And this is the error I am getting:

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 'long) VALUES ('test', '29/11/04 14:54', 'test', 'test')' at lin

I am connected to the database, and the table exists with all of those columns. As you can see, there is nothing that it being inserted into the database that should cause parsing errors.

Thanks,
Archy

Posted: Mon Nov 29, 2004 9:00 am
by Bill H
"Long" is a reserved word in MySQL. You need to put the column name in quotes or use a different name for the column.

Posted: Mon Nov 29, 2004 9:07 am
by Archy
: )

I suspected it would of been something like that; spose I should really start using `column`.
Thanks.

Posted: Thu Dec 02, 2004 9:16 am
by Dale
Im sure date is counted as a MySQL command too...

Posted: Thu Dec 02, 2004 11:43 am
by Bill H
Im sure date is counted as a MySQL command too...
Oddly enough, it's not.
See http://dev.mysql.com/doc/mysql/en/Reserved_words.html

Posted: Thu Dec 02, 2004 6:24 pm
by Archy
I knew date wasnt, that is why I use it, I didnt however at the time know that long was a reserved word.

Posted: Fri Dec 03, 2004 5:01 am
by Dale
Bill H wrote:
Im sure date is counted as a MySQL command too...
Oddly enough, it's not.
See http://dev.mysql.com/doc/mysql/en/Reserved_words.html

Thats odd... im sure a while back I had problems with the 'date' name... how strange?