j_mac
06-07-2005, 03:54 PM
I am trying to get this php script below to run daily as a cron job. I set it up using my website' Monster Controls "add/edit cron jobs" section. Basically it isn't working. I called tech support and they said that when it is run using the command line there is a syntax error. When it is run in the browser, it is fine. They indicated that parts of the script may need to be edited in order to work, but of course didn't say what that would be. Anyone have any ideas? I don't know much about cron jobs and the required syntax. The code for the php file is listed below (of course all connection details have been removed).
<?
$dbHost = "localhost";
$dbUser = "user";
$dbPass = "pass";
$dbName = "dbname";
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
@mysql_select_db($dbName);
$todays_date = date("F j, Y");
$max_time = strtotime("$todays_date 23:59:59");
$query = "SELECT * FROM pending_box WHERE send_on < '$max_time'";
$result = mysql_query($query);
$result_count = mysql_num_rows($result);
for ($i=0; $i<$result_count; $i++){
$thread = mysql_fetch_array($result);
$pending_id = $thread['pending_id'];
$recipient = $thread['recipient'];
$sender = $thread['sender'];
$sender_name = $thread['sender_name'];
$sender_id = $thread['sender_id'];
$message = $thread['message'];
$card_id = $thread['card_id'];
$send_time = $thread['send_on'];
$query = "INSERT INTO ecard_box
(recipient, sender, sender_name, sender_id, message, card_id, sent)
VALUES ('$recipient', '$sender', '$sender_name', '$sender_id', '$message', '$card_id', '$send_time')";
$result2 = mysql_query ($query);
if ($result2){
$header = "From:" . $sender . "\r\n";
$header .= "Reply-To:" . $sender . "\r\n";
$header .= "Content-Type: text/plain;\r\n charset=iso-8859-1\r\n";
$subject = "subject";
$body = "message";
mail ($recipient, $subject, $body, $header);
$to_trash[$i] = $pending_id;
}
}
if ($to_trash){
$num_trash = sizeof($to_trash);
for ($i=0; $i < $num_trash; $i++){
$tmp_id = $to_trash[$i];
$query = "DELETE FROM pending_box WHERE pending_id='$tmp_id'";
$result3 = mysql_query ($query);
}
}
?>
<?
$dbHost = "localhost";
$dbUser = "user";
$dbPass = "pass";
$dbName = "dbname";
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
@mysql_select_db($dbName);
$todays_date = date("F j, Y");
$max_time = strtotime("$todays_date 23:59:59");
$query = "SELECT * FROM pending_box WHERE send_on < '$max_time'";
$result = mysql_query($query);
$result_count = mysql_num_rows($result);
for ($i=0; $i<$result_count; $i++){
$thread = mysql_fetch_array($result);
$pending_id = $thread['pending_id'];
$recipient = $thread['recipient'];
$sender = $thread['sender'];
$sender_name = $thread['sender_name'];
$sender_id = $thread['sender_id'];
$message = $thread['message'];
$card_id = $thread['card_id'];
$send_time = $thread['send_on'];
$query = "INSERT INTO ecard_box
(recipient, sender, sender_name, sender_id, message, card_id, sent)
VALUES ('$recipient', '$sender', '$sender_name', '$sender_id', '$message', '$card_id', '$send_time')";
$result2 = mysql_query ($query);
if ($result2){
$header = "From:" . $sender . "\r\n";
$header .= "Reply-To:" . $sender . "\r\n";
$header .= "Content-Type: text/plain;\r\n charset=iso-8859-1\r\n";
$subject = "subject";
$body = "message";
mail ($recipient, $subject, $body, $header);
$to_trash[$i] = $pending_id;
}
}
if ($to_trash){
$num_trash = sizeof($to_trash);
for ($i=0; $i < $num_trash; $i++){
$tmp_id = $to_trash[$i];
$query = "DELETE FROM pending_box WHERE pending_id='$tmp_id'";
$result3 = mysql_query ($query);
}
}
?>