Syntax error

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

Syntax error

Postby multipianista » 03. October 2014 22:34

Hi, when I make a mysql consult it says that there's a syntax error, but I have checked it many times and I don't find the error. This is the consult:

Code: Select all
mysql_query("UPDATE p7lkt_content SET fulltext='$video' WHERE id='$primerid'");
echo mysql_error();


The thing is that if I create another column (exactly equal to 'fulltext', but with another name) it works, but not when I do with 'fulltext'. Where can be the error?

The error says: " 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 'fulltext=' "

Thanks for your time.
multipianista
 
Posts: 10
Joined: 24. January 2014 23:51
Operating System: Windows 8

Re: Syntax error

Postby Nobbie » 04. October 2014 10:04

"FULLTEXT" is a reserved MySQL Word (used for global text search), if you like to give a column the name "fulltext" (case does not matter), you have to enclose the column name into "backticks" (back single quote). In order to avoid collisions between column (or table) names and reserved words, you should either pay more attention or use backticks for all your fields:

Code: Select all
"UPDATE `p7lkt_content` SET `fulltext`='$video' WHERE `id`='$primerid'"


There remains a problem, because using backticks is a "MySQL only" syntax and if you like to bring your application to another SQL appplication, you will struggle with these backticks, as it is NON-ANSI SQL Standard. It is safer not to use reserved words. If you dont plan to change to another SQL, you may of course use backticks, as it provides an easy opportunity not to collide with reserved words.
Nobbie
 
Posts: 13179
Joined: 09. March 2008 13:04

Re: Syntax error

Postby multipianista » 04. October 2014 10:22

Ok it works, thanks. I supposed that it could be the problem but I didn't realise how problems can I have with that syntax. Thanks.
multipianista
 
Posts: 10
Joined: 24. January 2014 23:51
Operating System: Windows 8


Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 43 guests