Jump to content

Help With Reminder Script


derekshull

Recommended Posts

I have a script that I need some help with. Its a reminder script (posted below). Basically I have a completiondate (which in the database is a varchar...don't know if that makes a difference) that is made up like day, month, year (Ex: 06102012) and I want the script (which is a cron job) to look at todays date and see if it is 2 days before todays date. If it is then I want an email sent. I'm confused on where I'm going wrong. Please help! Thanks.

 

An example would be:

Todays date is: 06102012

If completiondate = 2 days before todays date

{

send email

}

 

$todaysdate = date('d/m/Y');
$query = "SELECT completiondate FROM needs WHERE completiondate =($todaysdate, strtotime('-1 days'))";
$result = mysql_query($query);

mail('derekshull@gmail.com', 'Important Stuff', 'Hey there.');
?>

Link to comment
Share on other sites

Did anyone else read the title as Reindeer? No? Just me? Ok.

 

 

Your code has no if statement in it, and no logic. What did you try so far?

 

strtotime is a php function, and won't work inside a string like that.

Edited by Jessica
Link to comment
Share on other sites

I tried this but no luck

 

 

 

$todaysdate = date('d/m/Y');

$query = "SELECT completiondate FROM needs";

$result = mysql_query($query);

 

$date = $rows['completiondate'];

if ($date = ($todaysdate - strtotime('-1 days'))) {

 

 

mail('derekshull@gmail.com', 'Important Stuff', 'Hey there.');

}

?>

Link to comment
Share on other sites

I've tried looking everywhere online too.

 

I'm basically needs a function that will get todays date and subtract 2 days away from the current date. Then if the record entry "completiondate" = that function date then it should send an email.

Edited by derekshull
Link to comment
Share on other sites

I recommend that you start in the PHP manual, and read the examples.

Reason I linked you to the "MySQLi" section is because the old "mysql" library is old, outdated and missing features from the new MySQL versions. Thus going to be removed in the future, and all new code should thus use the new and actively developed libraries instead.

Link to comment
Share on other sites

Ok so I thought I had it...but apparently not.

 

$query = "SELECT completiondate FROM needs WHERE completiondate IS NOT NULL";
$result = mysql_query($query);
while ($rows = mysql_fetch_array($result)) {
$completiondate = $rows['completiondate'];
$todaysdate = date("dmY");
$reminderdate = DATE_SUB($todaysdate, INTERVAL 2 DAY);
if ($completiondate = $reminderdate) {
mail('derekshull@gmail.com', 'Important Info', 'This stuff is importnat.');
}
}

 

I'm getting this error:

Parse error: syntax error, unexpected T_LNUMBER in /home/content/17/9932517/html/remindertwodaysbefore.php on line 29

 

Line 29 is where the $reminderdate is.

Link to comment
Share on other sites

So now I have this:

 

$query = "SELECT completiondate FROM needs WHERE completiondate = DATESUB(NOW(), INTERVAL 2 DAY)";
$result = mysql_query($query);

mail ('derekshull@gmail.com', 'hey', 'hey');

 

I've put the competiondate field as DATE

 

And I've set my completiondate to 2012-10-08

 

and it sent me an email.

 

But when I set it to another date it still sends me an email. Both past and future dates...i'm confused. I thought that would work.

Link to comment
Share on other sites

How many emails do you want to get? One for each row? Or one containing all the info for every row that matches?

 

And right now, you just told it to email you, with no logic.

Edited by Jessica
Link to comment
Share on other sites

Like this?:

 

$query = 'SELECT completiondate FROM needs WHERE completiondate = DATESUB(NOW(), INTERVAL 2 DAY)';
$result = mysql_query("SELECT completiondate FROM needs WHERE completiondate = DATESUB(NOW(), INTERVAL 2 DAY)");
while ($rows = mysql_fetch_array($result)) {

mail ('derekshull@gmail.com', 'hey', 'hey');
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.