Hi folks
I'm running a script to return the entries in a small membership database which should then work out who needs a renewal reminder, send the relevant email and then finally update the database to note that a reminder has been sent on the current date.
However, it's pulling back a number of records (I can see from the row count) and apparently stopping after successfully handling the the first one with the error:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
Here is the code I am using:
//send reminders to those who need them
echo "<h2>Reminders</h2><br />";
$count=0;
$sql_action="SELECT";
$sql_what="memno, forname, surname, email, reminder, renewdate";
$sql_from="FROM scopt";
$sql_where="WHERE status = 'a' AND renewdate != '0000-00-00'"; //default date accounts for some invalid records known to exist
include("../inc/submit.inc");
$rowsreturned = mysql_num_rows($result);
echo "$rowsreturned rows returned<br />";
if ($rowsreturned > 0) {
while($rows=mysql_fetch_row($result)){
$daysleft=dateDiff("-", "$date", "$rows[5]");
$sincerem=dateDiff("-", "$rows[4]", "$date");
if($daysleft<=30 AND $daysleft>0 AND $sincerem>15){
//Just checking up on it by echoing out a few vars!
echo "memno = $rows[0]<br />";
echo "Renewdate = $rows[5]<br />";
echo "Reminder date = $rows[4]<br />";
echo "days left = $daysleft <br />";
echo "time since reminder = $sincerem<br />";
$mailtype="reminder";
$memno=$rows[0];
$email=$rows[3];
$firstname=$rows[1];
$surname=$rows[2];
$rendate=dateshuffle($rows[5]);
include("send.php");
//Update renewal reminder field in database with current date
$sql_action="UPDATE";
$sql_what="";
$sql_from="scopt";
$sql_where="SET reminder = '$date' WHERE memno = '$memno'";
include("../inc/submit.inc");
$count++;
}
}
echo"$count reminders sent<br />";
}
For reference, the "submit.inc" used contains the following:
//setup connection
include('config.inc');
$connection = mysql_connect(DB_HOST , DB_USER , DB_PASS);
$db = mysql_select_db(DB_NAME , $connection);
// write query
$query="$sql_action $sql_what $sql_from $sql_where";
// echo "$query <br />";
// submit SQL
$result = mysql_query($query);
if ($result==""){echo "SQL failure! <br> $query <br>".mysql_error();}
else { }
unset($query);
mysql_close($connection);
Any suggestions at all as to why this might be happening would be gladly received!
Many thanks!