Jump to content

PHP Code IF Statement Help Needed


wantabe2

Recommended Posts

I have 99% of the code written but I still need a line or two but can't figure it out. Due_Attny is a date field. This code looks at my MySQL database & if the due_attny field is between todays date & the trigger date it will send an email to the $email variable. There is also a field in my MySQL database named a_mail_sent that by default is set to 0 which means an email has not been sent.

 

I need to edit this code so it will look at the a_email_sent field & if the value is 0, it sends the email & updates the a_email_sent field to 1 which means the email has been sent. If the a_mail_sent field has a value of 1, I don't need the email to be sent.

 

Can somoeone help me out with this code? Thanks

 

 


<?php
include('connection.php'); // DB connection
// Constants
$number_of_days_before = 6;
$email = "emailaddress@mail.org";
$reminder_details = "";
$todays_date = date( "Ymd" );
echo $todays_date;
$year = substr($todays_date, 0, 4);
$month = substr($todays_date, 4, 2);
$date = substr($todays_date, 6, 2);
$trigger_date = date("Ymd", mktime(0,0,0,$month, $date+$number_of_days_before,$year));
$insertquery = "UPDATE psrinfo SET a_mail_sent=1 WHERE employee='Employee1'";
mysql_query($insertQuery) or die ('Error updating database'); 

echo $trigger_date;

$result = mysql_query( "SELECT a_mail_sent, due_attny, employee, pacts, dock, fname, lname FROM psrinfo WHERE employee='Employee1' AND due_attny BETWEEN $todays_date AND $trigger_date" );
$nr = mysql_num_rows( $result );

while( $row = mysql_fetch_array( $result ) )
{
$reminder_details .= "Name: ".$row["fname"]." ".$row["lname"]."\n";
$reminder_details .= "PACTS Number: ".$row["pacts"]."\n";
$reminder_details .= "Dock: ".$row["dock"]."\n";
$reminder_details .= "Due to Attny: ".$row["due_attny"]."\n\n\n";
}
mysql_free_result( $result );
if( !empty( $nr ) )
{
// Send reminder email
$mailheader = "From: Reminder System <$email>\nX-Mailer: Reminder\nContent-Type:text/plain";
mail("$email", "PSR Due Within 6 Days", "$reminder_details", "$mailheader");

}
?>

Link to comment
Share on other sites

im not exactly sure if this is what you want but you  can try this;

 

<?php
include('connection.php'); // DB connection
// Constants
$number_of_days_before = 6;
$email = "emailaddress@mail.org";
$reminder_details = "";
$todays_date = date( "Ymd" );
echo $todays_date;
$year = substr($todays_date, 0, 4);
$month = substr($todays_date, 4, 2);
$date = substr($todays_date, 6, 2);
$trigger_date = date("Ymd", mktime(0,0,0,$month, $date+$number_of_days_before,$year));

echo $trigger_date;

$result = mysql_query( "SELECT a_mail_sent, due_attny, employee, pacts, dock, fname, lname FROM psrinfo WHERE employee='Employee1' AND due_attny BETWEEN $todays_date AND $trigger_date" );
$nr = mysql_num_rows( $result );

$sent = mysql_query( "SELECT a_mail_sent FROM psrinfo WHERE employee='Employee1' AND due_attny BETWEEN $todays_date AND $trigger_date" );
$rows = mysql_fetch_array( $sent )

while( $row = mysql_fetch_array( $result ) )
{
$reminder_details .= "Name: ".$row["fname"]." ".$row["lname"]."\n";
$reminder_details .= "PACTS Number: ".$row["pacts"]."\n";
$reminder_details .= "Dock: ".$row["dock"]."\n";
$reminder_details .= "Due to Attny: ".$row["due_attny"]."\n\n\n";
}
mysql_free_result( $result );
if( $rows == "0" )
{
// Send reminder email
$mailheader = "From: Reminder System <$email>\nX-Mailer: Reminder\nContent-Type:text/plain";
mail("$email", "PSR Due Within 6 Days", "$reminder_details", "$mailheader");

mysql_query("UPDATE psrinfo SET a_mail-sent='1' WHERE employee='Employee1'") 
or die(mysql_error());  

}
?>

Link to comment
Share on other sites

Okay, I forgot about my unique FID filed for each record....Please see this code...to see if someone can find my problems...I get the following errors:

 

" Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\flow\query\reminders\mail.php on line 16"

 

" Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\flow\query\reminders\mail.php on line 18"

 

" Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\flow\query\reminders\mail.php on line 28"

 

 

<?php
include('connection.php'); // DB connection
// Constants
$number_of_days_before = 6;
$email = "email@mail.org";
$reminder_details = "";
$todays_date = date( "Ymd" );
echo $todays_date;
$year = substr($todays_date, 0, 4);
$month = substr($todays_date, 4, 2);
$date = substr($todays_date, 6, 2);
$trigger_date = date("Ymd", mktime(0,0,0,$month, $date+$number_of_days_before,$year));
echo $trigger_date;

$result = mysql_query( "fid, a_mail_sent, due_attny, employee, pacts, dock, fname, lname FROM psrinfo WHERE employee='Employee1' AND due_attny BETWEEN $todays_date AND $trigger_date AND a_mail_sent = 0" );
$nr = mysql_num_rows( $result );

while( $row = mysql_fetch_array( $result ) )
{
mysql_query( "UPDATE psrinfo SET a_mail_sent = 1 WHERE fid = " . $row["fid"] . " " );


$reminder_details .= "Name: ".$row["fname"]." ".$row["lname"]."\n";
$reminder_details .= "PACTS Number: ".$row["pacts"]."\n";
$reminder_details .= "Dock: ".$row["dock"]."\n";
$reminder_details .= "Due to Att: ".$row["due_attny"]."\n\n\n";
}
mysql_free_result( $result );
if( !empty( $nr ) )
{
// Send reminder email
$mailheader = "From: Reminder System <$email>\nX-Mailer: Reminder\nContent-Type:text/plain";
mail("$email", "PSR Due Within 6 Days", "$reminder_details", "$mailheader");

}
?>


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.