Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

    Delete from old messages not working

    I set up a cron job to run every 6 hours to delete old messages from users past 60 days old. But it won't work. This is the entire coding excluding the database username and password stuff.

    Code:
    <?php
    
    $postdate = date(
        'Y-m-d H:i:s', // 0000-00-00 00:00:00
        time() - ( 60 * 60 * 24 * 60 ) //  60 days into the past
    );
    mysql_query( "DELETE FROM `messages` WHERE `postdate` < '{$postdate}'" ) or exit( mysql_error() );
    
    ?>

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    What MySQL error is displayed, if any?

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    The cron doesn't send me an email, and it doesn't delete the messages. If I run it myself it doesn't do anything, it's a blank page (which is normal there is no text in it) and no errors are displayed.

  • #4
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Quote Originally Posted by masterofollies View Post
    The cron doesn't send me an email, and it doesn't delete the messages. If I run it myself it doesn't do anything, it's a blank page (which is normal there is no text in it) and no errors are displayed.
    Does the script do it's job when you execute it though? If so, it's cron. If not, it's PHP.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Nope if I run it manually then it does nothing.

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    I tried changing the < to a > and that made all messages be deleted. So if that works then the query does in fact work, but just the time isn't working.

  • #7
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by masterofollies View Post
    I tried changing the < to a > and that made all messages be deleted.
    Of course... I already went over that with you.

    Are you sure there were messages older than 60 days in there?
    Last edited by kbluhm; 07-24-2008 at 03:28 PM.

  • Users who have thanked kbluhm for this post:

    masterofollies (07-25-2008)

  • #8
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    I'm starting to think something may be wrong with your time statements but I'm so poor with that I don't want to risk giving you advice on it until you exhaust your other options .
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • #9
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Yeah I had some from May 2nd. But it looks like it did delete a few pages worth. Let me run a test of like 59 days and like 20 hours and see if it disappears.

  • #10
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Ok it really does work now. Thanks!!!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •