My webpage runs the following code every time someone goes to it. My query goes out to the referrals table and checks to see if a particular row has a date in the “arrived” column. If “arrived” is null, then my script attempts to do an insert into the notifications table. The problem is that its doing the insert every time the page is loaded, even when that particular referral already has an “arrived” date. Am I using (mysql_num_rows($result)==0) correctly in this instance?
$insertNotification = "INSERT INTO notifications (date, priority, type, sender, recipient, subject, message) VALUES (
'$longDate',
'1',
'$type',
'$sender',
'$guideEmail',
'$subject',
'$message')";
$alreadyLogged = "SELECT date FROM referrals WHERE rID = '$rID' and arrived is null";
$result = mysql_query($alreadyLogged) or die("<b>A fatal MySQL error occurred</b>.\
<br />Query: " . $sql . "<br />\
Error: (" . mysql_errno() . ") " . mysql_error());
if (mysql_num_rows($result)==0) {
mysql_query($insertNotification) OR die("<b>A fatal MySQL error occurred</b>.\
<br />Query: " . $insertNotification . "<br />\
Error: (" . mysql_errno() . ") " . mysql_error());
}