MySQL Error: "WHERE post LIKE" not working

Go To StackoverFlow.com

1

I'm not a MySQL expert and am having problem with this...

So, I have a forum board database. There is an outdated code in one of the table that I need to replace. I'm trying to use this:

Update ibf_posts
Set    post = replace(post, '<div width="95%" style="margin:8px 26px 4px 26px"><a href="javascript:void(0);" onclick="javascript:spoil(this);"><div class=\'spoilertop\'><b>SPOILER</b> [Show/Hide]</div></a><div style="display: none;" class="spoilermain">', '<div width="95%" style="margin:8px 26px 4px 26px"><a class=\'spoilertop\' style=\'display:block;\'><b>SPOILER</b> [Show/Hide]</a><div class="spoilermain">');
WHERE  post LIKE '%<div width="95%" style="margin:8px 26px 4px 26px"><a href="javascript:void(0);" onclick="javascript:spoil(this);"><div class=\'spoilertop\'><b>SPOILER</b> [Show/Hide]</div></a><div style="display: none;" class="spoilermain">%';

But it's not working. It says:

#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 'WHERE  post LIKE '%<div width="95%" style="margin:8px 26px 4px 26px"><a href="ja' at line 1 

It's odd, since I tried on my localhost it's working fine. But when I tried in my live server, it doesn't work. My MySQL version (on live server) is MySQL 4.1.22.

Any help?

2012-04-03 21:16
by deathlock


4

You should remove the semicolon at the end of the second line, as it indicates that the query is ending, which is not true.

2012-04-03 21:19
by Daniel Rotter
Whoa, quick answer. Thanks! I wonder though, with the exact same code it is working in localhost, but it's not working in live server. Why is it - deathlock 2012-04-03 21:24
Hm, actually it should also not work on localhost, of course. Is this query generated? And is it working correctly - Daniel Rotter 2012-04-04 20:07


1

Second line has a ; at the end. When you erase it then query works

2012-04-03 21:20
by Jarosław Gomułka
Thanks! But I wonder, with the exact same code it is working in localhost, but it's not working in live server; why is it - deathlock 2012-04-03 21:29


1

The semicolon (;) is used to terminate the query ,means we use only one semicolon in the end of every query not in the middle.

I am shocked that your code worked on localhost. Have you checked that the query have worked exactly what you want on localhost or it was doing something else.

2012-04-04 05:47
by Ankit Sharma