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('[email protected]', 'Important Stuff', 'Hey there.');
?>

Link to comment
https://forums.phpfreaks.com/topic/269177-help-with-reminder-script/
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('[email protected]', 'Important Stuff', 'Hey there.');

}

?>

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.

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('[email protected]', '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.

So now I have this:

 

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

mail ('[email protected]', '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.

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 ('[email protected]', 'hey', 'hey');
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.