How to remove strings with regexp from the database?

Discussion in 'MySQL' started by Devtard, Mar 21, 2013.

Thread Status:
Not open for further replies.
  1. #1
    My friend's Joomla website was hacked and now there are Javascript codes at the end of every post in the database.

    The code always begins with "<script" and ends with "</script>". Any idea how to remove that (manual removing is out of the question).

    --
    I found this script but for some reason I get syntax errors. :oops:

    <?php
    //login information
     
        $selectQuery = "SELECT `id`, `fulltext` FROM content";
     
        $res = mysql_query($selectQuery, $co) or exit(mysql_error());
     
     
        while($row = mysql_fetch_assoc($res))
        {
            $updateQuery =  "UPDATE content SET fulltext = '". addslashes(preg_replace("/<script(.*)<\/script>/", '', $row['fulltext'])) ."' WHERE ID = " . $row['id'];
     
     
     
        mysql_query($updateQuery) or exit(mysql_error());
        }
     
        mysql_close($co);
     
    ?>
    Code (markup):
     
    Devtard, Mar 21, 2013 IP
Thread Status:
Not open for further replies.