Insert problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Insert problem

Post 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
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

: )

I suspected it would of been something like that; spose I should really start using `column`.
Thanks.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Im sure date is counted as a MySQL command too...
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post 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.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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?
Post Reply