homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

find and replace text with where statement

 1:27 am on Aug 29, 2011 (gmt 0)


I am trying to find and replace text in my db with mysql. I think the code is correct but it is not replacing any text? Offer any suggestions?

UPDATE db SET field= replace(field,'<script type="text/javascript">// <![CDATA[
google_ad_client = "pub-number";
/* 336x280, created 12/24/10 */
google_ad_slot = "number";
google_ad_width = 336;
google_ad_height = 280;
// ]]></script>
<script src="webpage" type="text/javascript">
</script>','<br />') Where field like 'Song%';

Any help would be appreciated.

Best regards,



 6:21 pm on Aug 29, 2011 (gmt 0)

First, using phpMyAdmin or the mysql command line, try the query:

SELECT * FROM db WHERE field LIKE 'Song%';

This will show you the records that the query will update. If it doesn't return any records, then the table name, field name, or value to find is wrong.

Assuming the above works, I suspect you're running into a problem with the replacement string not exactly matching what is in the databases. It's going to be difficult to handle because of the embedded line feeds and, possibly, embedded spaces that aren't obvious.

You could do something like:

UPDATE db SET field=REPLACE('src="webpage"', 'id="webpage"', field) WHERE field LIKE 'Song%';

The above won't remove the Adsense code, but will make it inert.

-- Roger


 1:22 am on Aug 30, 2011 (gmt 0)

thanks roger. I will check it out.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved