Hi everyone! I hope I can get some help with this script. I had this written but it has never worked just right for me, this script is a Cron Job that runs every night.
The function of the script is to query the Database for entries that have dates that are 2 weeks out. For example:
The Script runs every night ans sends a a corresponding email two weeks in advance of the date that is queried.
The page that the information is collected from is here:
http://www.jtschmids.com/guestloyalty.php
and the Script that is to run every night is this code:
#!/usr/bin/php -q
<?php
$dblink = mysql_pconnect('localhost','******','******');
mysql_select_db('jtschmids_loyalty');
list ($script, $event, $template, $subject, $daysOut, $trimDuplicates) = $argv;
$templateRaw = join('', file($template));
$query = "SELECT firstname, lastname, email, zipcode, $event FROM guest_info WHERE ";
$query .= "DATE_FORMAT($event, '%m-%d') = DATE_FORMAT(NOW() + INTERVAL $daysOut day, '%m-%d') ";
$query .= ($trimDuplicates) ? ' GROUP BY 5, 1, 2 ' : '';
$res = mysql_query($query);
if (!$res) {
print(mysql_error() . "\n");
}
$matchCount = mysql_num_rows($res);
// The following line should only be uncommented if you're watching the script run.
// print("$matchCount found.\n");
for ($i = 0 ; $i < mysql_num_rows($res) ; $i++) {
$row = mysql_fetch_object($res);
// The following line should only be uncommented if you're watching the script run.
// print("Sending email to " . $row->email . "...\n");
$toAddress = $row->email;
// Uncomment the following line to send all emails to a specific address, for testing.
// $toAddress = 'offnetrob@yahoo.com';
mail($toAddress, $subject, $templateRaw, "From: JT Schmid's <noreply@jtschmids.com>\nContent-type: text/html");
}
?>
The Templates that are supposed to be emailed are:
http://www.jtschmids.com/bday_anniversary/anniversary.html
http://www.jtschmids.com/bday_anniversary/birthday.html
The script did work at one time. Now when it is executed (
http://www.jtschmids.com/cron/loyalty.php) I get the error:
#!/usr/bin/php -q
Warning: join(): Bad arguments. in /home/virtual/site2/fst/var/www/html/cron/loyalty.php on line 9
You have an error in your SQL syntax near 'FROM guest_info WHERE DATE_FORMAT(, '%m-%d') = DATE_FORMAT(NOW() + INTERVAL day' at line 1
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/virtual/site2/fst/var/www/html/cron/loyalty.php on line 19
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/virtual/site2/fst/var/www/html/cron/loyalty.php on line 24
Does anyone know what I need to change in order for this to execute properly???