1

I wrote this query for a joomla plugin

$query = "UPDATE #__content SET fulltext='$_POST[statenames]' WHERE id=$articleId";

But it gives 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 'fulltext = '1' WHERE id = 41' at line 1 SQL=UPDATE jst_content SET fulltext = '1' WHERE id = 41

What is the error?

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
Ajith
  • 305
  • 1
  • 3
  • 10

1 Answers1

2

FULLTEXT is a MySQL Reserved Keyword. You must wrap the column with backtick.

$query = "UPDATE #__content SET `fulltext` = '$_POST[statenames]' WHERE id=$articleId";

As a sidenote, the query is vulnerable with SQL Injection if the value of the variable(s) came from clients. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements you can get rid of using single quotes around values.

Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492