0

Hello All,

Having a few problems with the code below and wondered if someone could shed some light on it, I have a php script running from a cron that runs every 15 mins the error I am getting tom the cron is

PHP Notice: Undefined variable: rows in /var/www/vhosts/server.com/migration_tracker/staff/5th_email.php on line 9

My code is

<?php 

include('config.inc');

$agree_date = $rows['agree_date'];

if ($agree_date > strtotime('2 week')) { 


mysql_select_db($dbname); 
$sql="SELECT * FROM db, 5th_email WHERE old_mbox_del = '0' AND 1st_email_sent = '1' AND 2nd_email_sent = '1' AND 4th_email_sent = '1' AND 5th_email_sent = '0' AND 6th_email_sent = '0'"; 
$result = mysql_query($sql) or die(mysql_error());

$count = 1;
while ($rows = mysql_fetch_array ($result)) {

$to  = $rows['contact_email']; 
$from = "support@domain";
$subject = "Migration Team";
$message = $rows['body'];
$headers = "From:" . $from; 
mail($to,$subject,$message,$headers);
    if ($count % 5 == 0) {
      sleep(5);
    }
    $count++;
}
$sql="UPDATE tracker_db SET 5th_email_sent ='1' WHERE 6th_email_sent ='0' AND 1st_email_sent = '1' AND 2nd_email_sent = '1' AND 4th_email_sent = '1' AND 5th_email_sent = '0' AND old_mbox_del = '0'";
$result=mysql_query($sql);

}
mysql_close();
?>

I think the problem is I havn't declared $agree_dat correctly or havn't selected from the db, could this be the cuase

Cheers
Martin

Edited by urbanthistleuk

4
Contributors
21
Replies
73
Views
3 Years
Discussion Span
Last Post by urbanthistleuk
Featured Replies
  • 1
    diafol 3,720   3 Years Ago

    Just because it didn't work doesn't mean that your original code was better. I would suggest that you made incremental improvements. Use SVN or similar to keep versions, then you can dust off the best one to work on. No need to go back to square 1. Read More

0

Your title is misleading. It's not a cron issue, is it? Which line in your code is this error attributed to. I know it says line 9, but there's nothing there in your code.

$agree_date = $rows['agree_date'];

Seems like the culprit. Where is $rows declared before this?

0

Sorry for the misleading title, thaught it was related to the cron as the error where being sent out by the cron deamon :)

Line 9 refered to

$agree_date = $rows['agree_date'];

as I did try an put a select all stament in but didn't work, I havn't declared $rows before it, thaught it may have been somthing like that

Edited by urbanthistleuk

0

I'm not sure what you want from us. The line mentioned will obviously fail. So what do you need to do? Run a query before that?

0

Sorry for the confusion, has been one of those mornings :) Yeah I have added a query to my code just about to check it, Thanks for your help

0

I have updated my code to this

<?php 

include('config.inc');

$sql="SELECT * FROM tracker_db";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);

$agree_date = $rows['agree_date'];

if ($agree_date > strtotime('2 week')) { 


mysql_select_db($dbname); 
$sql="SELECT * FROM db, 5th_email WHERE old_mbox_del = '0' AND 1st_email_sent = '1' AND 2nd_email_sent = '1' AND 4th_email_sent = '1' AND 5th_email_sent = '0' AND 6th_email_sent = '0'"; 
$result = mysql_query($sql) or die(mysql_error());

$count = 1;
while ($rows = mysql_fetch_array ($result)) {

$to  = $rows['contact_email']; 
$from = "support@domain";
$subject = "Migration Team";
$message = $rows['body'];
$headers = "From:" . $from; 
mail($to,$subject,$message,$headers);
    if ($count % 5 == 0) {
      sleep(5);
    }
    $count++;
}
$sql="UPDATE db SET 5th_email_sent ='1' WHERE 6th_email_sent ='0' AND 1st_email_sent = '1' AND 2nd_email_sent = '1' AND 4th_email_sent = '1' AND 5th_email_sent = '0' AND old_mbox_del = '0'";
$result=mysql_query($sql);

}
mysql_close();
?>

I am now gertting

PHP Notice: Undefined variable: rows in /var/www/vhosts/server.com/migration_tracker/staff/5th_email.php on line 9

Think is must be somthing to do witnh the query what to you reckon

Cheers
Martin

0

Yeah have treid mysql_select_db() and got the following

PHP Parse error: syntax error, unexpected T_STRING in /var/www/vhosts/server.com/migration_tracker/staff/5th_email.php on line 7

0
<?php 

include('config.inc');

mysql_connect()

mysql_select_db($dbname); 
$sql="SELECT * FROM tracker_db";
$result=mysql_query($sql);

$agree_date = $rows['agree_date'];

$rows=mysql_fetch_array($result);


if ($agree_date > strtotime('2 week')) { 


mysql_select_db($dbname); 
$sql="SELECT * FROM db, 5th_email WHERE old_mbox_del = '0' AND 1st_email_sent = '1' AND 2nd_email_sent = '1' AND 4th_email_sent = '1' AND 5th_email_sent = '0' AND 6th_email_sent = '0'"; 
$result = mysql_query($sql) or die(mysql_error());

$count = 1;
while ($rows = mysql_fetch_array ($result)) {

$to  = $rows['contact_email']; 
$from = "support@domain";
$subject = "Migration Team";
$message = $rows['body'];
$headers = "From:" . $from; 
mail($to,$subject,$message,$headers);
    if ($count % 5 == 0) {
      sleep(5);
    }
    $count++;
}
$sql="UPDATE db SET 5th_email_sent ='1' WHERE 6th_email_sent ='0' AND 1st_email_sent = '1' AND 2nd_email_sent = '1' AND 4th_email_sent = '1' AND 5th_email_sent = '0' AND old_mbox_del = '0'";
$result=mysql_query($sql);

}
mysql_close();
?>
0

Assuming your connection doesn't run
in config.inc you need to fill in the mysql_connect() in the above code with the variables from the file, for instance:
mysql_connect($host, $user, $password) or die(mysql_error());

Also this bit of code is backwards again:

11. $agree_date = $rows['agree_date'];
12. 
13. $rows=mysql_fetch_array($result);

You fundamentally cannot use data from an array before it has been put there.

0

Thanks, have made some changes still having problems,

Care to share?

0

Hello,

Yeah no probs have made a slight change but I am getting lost with it now, kind of working to a deadline :(

<?php 

include('config.inc');


$date = $row['agree_date'];

if ($date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week"); { 

mysql_select_db($dbname); 
$sql = "SELECT * FROM db, 5th_email WHERE old_mbox_del = '0' AND 1st_email_sent = '1' AND 2nd_email_sent = '1' AND 4th_email_sent = '1' AND 5th_email_sent = '0' AND 6th_email_sent = '0'"; 
$result = mysql_query($sql) or die(mysql_error());

$count = 1;
while ($rows = mysql_fetch_array ($result)) {

$to  = $rows['contact_email']; 
$from = "support@domain";
$subject = "Migration Team";
$message = $rows['body'];
$headers = "From:" . $from; 
mail($to,$subject,$message,$headers);
    if ($count % 5 == 0) {
      sleep(5);
    }
    $count++;
}
$sql="UPDATE db SET 5th_email_sent ='1' WHERE 6th_email_sent ='0' AND 1st_email_sent = '1' AND 2nd_email_sent = '1' AND 4th_email_sent = '1' AND 5th_email_sent = '0' AND old_mbox_del = '0'";
$result=mysql_query($sql);

}
mysql_close();
?>

Cheers
Martin

0

Dear UTUK

You have been advised countless (it seems) times about this line...

$date = $row['agree_date'];

Unless you've placed some inappropriate code into config.inc, then that will never work as $row does not exist yet.

0

ok let me check, I have tried it in many ways and chnaged waht I have been advised I have put it back to the way it was cause it didnt work

1

Just because it didn't work doesn't mean that your original code was better. I would suggest that you made incremental improvements. Use SVN or similar to keep versions, then you can dust off the best one to work on. No need to go back to square 1.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.