Thread: Code Help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Code Help


    I was hoping you guys could help me with this bit of code. Everything else is working fine except for this part.

    I set a cron job to run it, and it is suppose to go into each of my wordpress databases and replace the terms [STARTPOSTCONTENT] etc, but I keep getting this error message:

    "<br />
    <b>Parse error</b>: syntax error, unexpected ';' in <b>/home/xxxxx/public_html/change_status.php</b> on line <b>134</b><br />"

    The first line you guys see here is line 134.

    $query = $pdo->prepare("UPDATE wp_posts SET post_content = REPLACE (post_content, \'[STARTPOSTCONTENT]\', \' \')";
    $query->execute();
    $query = $pdo->prepare("UPDATE wp_posts SET post_content = REPLACE (post_content, \'[POSTCONTENT]\', \' \')";
    $query->execute();
    $query = $pdo->prepare("UPDATE wp_posts SET post_content = REPLACE (post_content, \'[ENDPOSTCONTENT]\', \' \')";
    $query->execute();
    $query = $pdo->prepare("UPDATE wp_posts SET post_content = REPLACE (post_content, \'[STARTVIDEO]\', \' \')";
    $query->execute();
    $query = $pdo->prepare("UPDATE wp_posts SET post_content = REPLACE (post_content, \'[VIDEO]\', \' \')";
    $query->execute();
    $query = $pdo->prepare("UPDATE wp_posts SET post_content = REPLACE (post_content, \'[ENDVIDEO]\', \' \')";
    $query->execute();
    }
    ?>
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    Maybe it'll be easier to see with a much shorter SQL query:
    PHP Code:
    $query $pdo->prepare("query"
    They're all like that.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0
    $query = $pdo->prepare("UPDATE wp_posts SET post_content = REPLACE (post_content, \'[STARTPOSTCONTENT]\', \' \')";

    So I figured out the parse error by putting an extra parenthesis at the end after I realized I had two, (, and only one , ),

    So now it looks like

    $query = $pdo->prepare("UPDATE wp_posts SET post_content = REPLACE (post_content, \'[STARTPOSTCONTENT]\', \' \')");


    so it runs without an error, but it still not having the desired outcome.

    I need it to be able to access all the wordpress databases I own and the [start post content] but for some reason I just can't figure it out. As far as I can tell, it is written correctly, but I just can't figure it out for some reason.

    Do you guys have any suggestions?

    Thanks!
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    Right now it's updating one field in one table in one database. Are you saying there's more it should be updating?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0
    Yea, I have about 100 databases that have shortcode [start post content], [end post content], [start video], [video], and [end video], that I wanted to delete. Its for a wordpress blogs,

    but got it straightened out and fixed

    $search = array('[STARTPOSTCONTENT]','[POSTCONTENT]','[ENDPOSTCONTENT]','[STARTVIDEO]','[VIDEO]','[ENDVIDEO]');

    foreach($search as $s){
    $query = $pdo->prepare("UPDATE wp_posts set post_content = REPLACE(post_content,'{$s}','') where post_status = 'publish'");
    $query->execute();

IMN logo majestic logo threadwatch logo seochat tools logo