Kombuwa
Kombuwa

Reputation: 1651

SQL REPLACE give error in phpmyadmin

UPDATE 'module_tests' SET 'tests_content' = REPLACE('tests_content', '<a onclick=', '<a class="dic"  onclick=');

When I am tried to run top query in phpmysql it gave bellow error. Can someone tell me the reason for this?

#1064 - 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 ''module_tests' SET 'tests_content' = REPLACE('tests_content', '<a onclick=', '' at line 1

Upvotes: 1

Views: 1171

Answers (2)

Akash KC
Akash KC

Reputation: 16310

Remove the single quote around the table and column name..Your query should be like this:

UPDATE module_tests SET tests_content = REPLACE(tests_content, '<a onclick=', '<a class="dic"  onclick=');

Check out SQLFIDDLE

I suspect, you have some confusion about single quote(') and backtick(`). In your example, you can use backtick to ensure that your table name and field name do not get conflict with reserved words in mysql.... Using backtick, you can modify your query like this:

UPDATE `module_tests` SET `tests_content` = REPLACE(`tests_content`, '<a onclick=', '<a class="dic"  onclick=');

Check out Query With Backtick

Upvotes: 2

MISJHA
MISJHA

Reputation: 1008

change the query to this:

UPDATE `module_tests` 
   SET `tests_content` = REPLACE(`tests_content`, '<a onclick=', '<a class="dic"  onclick=');

You are passing the table and column name as strings.

Upvotes: 0

Related Questions