Cron Job

Discussion in 'PHP' started by prabash82, Jul 31, 2009.

  1. #1
    i have developed a submission form with 10 fields.when user submit the form data send in to the MYSQL data base.Now i want to send that data to my client' email address week by week.how to do this cron job. I don't have idea how to write this PHP script. Any one can help me...........

    Thanks
     
    prabash82, Jul 31, 2009 IP
  2. ptalent

    ptalent Peon

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Does your host have cron tab?

    If not, it is possible to do it by ssh
     
    ptalent, Jul 31, 2009 IP
  3. codebreaker

    codebreaker Well-Known Member

    Messages:
    281
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #3
    A short idea for you.add a new field in the database where you can store the time ( time or date ) when the entry was inserted.
    Then create a a php file that will mail all the entries in the last 7 days.
    And then run this cronjob every 7 days.
    I hope you got what i meant.
    Codebreaker.
     
    codebreaker, Jul 31, 2009 IP
  4. Ntech

    Ntech Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The traditional approach to handling form submissions is to just have the script sanitize the entered data and send it immediately to an e-mail address.

    Is there a reason why your client wants it at the end of each week?

    Why not have your client setup a special email address for the script to immediately send the data to and he can just go through the in-box at the end of the week or whenever he wants.
     
    Ntech, Jul 31, 2009 IP
  5. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You could try something like this:

    
    $since_last_week = date('Y-m-d', strtotime('-1 week'));
    $today = date('Y-m-d');
    $sql = 'SELECT * FROM submissions WHERE created_at >= "' . mysqli_real_escape_string($since_last_week) . '" AND created_at < "' . mysqli_real_escape_string($today) . '"';
    
    PHP:
    Then construct the email within the foreach loop and send it off at the end. Set up your cron so that this executes once per week.
     
    premiumscripts, Aug 3, 2009 IP