Friend Adder cron job stopped working

Discussion in 'PHP' started by mike323, May 12, 2010.

  1. #1
    Can anyone help me on this?

    I have a friend adder site for blogtv members: webcamadds.com

    Someone set up a cron job for me awhile ago that is supposed to reset the points for all the site's users at midnight each night.

    But it's not resetting the points.

    This is what the code looks like in the reset.php file:

    <?php
    include('../sqlc.php');
    
    // Reset site at midnight
    
    mysql_query("TRUNCATE added");
    mysql_query("UPDATE members SET
            points='0', added='0', referrals='0', requests='0'");
    mysql_query("UPDATE members SET daysleft=daysleft-1
            WHERE daysleft > 0");
    mysql_query("OPTIMIZE TABLE members");
    mysql_query("OPTIMIZE TABLE news_comments");
    ?>
    Code (markup):
    lynx -dump http://webcamadds.com/assets/c/reset.php /dev/null 2>&1
    Code (markup):

     
    mike323, May 12, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    you need to put in some logging or error handling.

    Perhaps this would be useful. If a query fails then it gets emailed to you before it shuts down. then when its all done it emails you too... if it gets that far.

    include('../sqlc.php');
    
    // Reset site at midnight
    function runSql($sql) {
            mysql_query($sql) or die(mail('me@mysite.com', 'Cron Failure: '.date('d-m-Y'), $sql));
    }
    
    runSql("TRUNCATE `added`");
    runSql("UPDATE `members` SET `points`='0', added='0', `referrals`='0', `requests`='0'");
    runSql("UPDATE `members` SET `daysleft`=`daysleft`-1 WHERE `daysleft` > 0");
    runSql("OPTIMIZE TABLE `members`");
    runSql("OPTIMIZE TABLE `news_comments`");
    
    mail('me@mysite.com', 'Success: '.date('d-m-Y'), 'The cron job completed');
    
    PHP:
     
    sarahk, May 12, 2010 IP
  3. mike323

    mike323 Well-Known Member

    Messages:
    1,594
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Okay, I think I see. I'll try this. Thank you!

     
    Last edited: Jun 27, 2010
    mike323, Jun 27, 2010 IP
  4. mike323

    mike323 Well-Known Member

    Messages:
    1,594
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    160
    #4
    Well, i used the code you posted and it sent me a single query failure email notification so it is still not resetting the points.

    anyone have any suggestions for fixing this?

    thank you.
     
    mike323, Jun 29, 2010 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #5
    which query did it fail on? this one?
    runSql("UPDATE `members` SET `points`='0', added='0', `referrals`='0', `requests`='0'");
    Code (markup):
    what happens when you run it from phpMyAdmin/SqlYog etc? what error do you get?
     
    sarahk, Jun 29, 2010 IP
  6. mike323

    mike323 Well-Known Member

    Messages:
    1,594
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    160
    #6
    Well, this is all that was in the error email:

    Cron <blogtv@srv1> lynx -dump http://webcamadds.com/assets/c/reset.php /dev/null 2>&1

    I'm sorry, I wouldn't know how to run it from phpMyAdmin. Do I just paste the code into the SQL text box field and save it?
     
    mike323, Jun 29, 2010 IP
  7. mike323

    mike323 Well-Known Member

    Messages:
    1,594
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    160
    #7
    Okay, I was able to run it from phpMyAdmin/sqlyog and this is what I got:

    There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem

    ERROR: Unknown Punctuation String @ 1
    STR: <?
    SQL: <?php
    include('../sqlc.php');<?php
    include('../sqlc.php');<?php
    include('../sqlc.php');<?php
    include('../sqlc.php');<?php
    include('../sqlc.php');<?php
    include('../sqlc.php');<?php
    include('../sqlc.php');<?php
    include('../sqlc.php');<?php
    include('../sqlc.php');<?php
    include('../sqlc.php');


    SQL query:

    <?php include('../sqlc.php');

    MySQL said: Documentation
    #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 '<?php
    include('../sqlc.php')' at line 1
     
    mike323, Jul 8, 2010 IP