I have a mailsystem on my website.
Everytime I execute CleanMailBox on the specified player_id , I want the script to check if the user have more messages than allowed , and if so , delete the oldest one to make room for the new one.
function CleanMailBox($pid) {
mysql_connect("localhost","root","b1qxsc35stdq99st") or die('MySQL error!');
mysql_select_db("neomaster_filedb") or die('MySQL error!');
$query = mysql_query("SELECT COUNT(message_id) as nbmail, MIN(message_id) as oldmail FROM mail_link WHERE player_id='$pid'");
$NbMsg = mysql_result($query, "nbmail");
//If the mailbox is full, delete the oldest message
if ($NbMsg > 2) {
$OldestMessage = mysql_result($query, "oldmail");
$Query = "DELETE FROM mail_link WHERE message_id = $OldestMessage";
sql_query($Query);
return 2;
}
return 1;
}
But this function doesn't works. I'm getting error saying that : Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/neomaster/ on line 18
(BTW , line 18 is the first mysql_result in this function.)
Everytime I execute CleanMailBox on the specified player_id , I want the script to check if the user have more messages than allowed , and if so , delete the oldest one to make room for the new one.
function CleanMailBox($pid) {
mysql_connect("localhost","root","b1qxsc35stdq99st") or die('MySQL error!');
mysql_select_db("neomaster_filedb") or die('MySQL error!');
$query = mysql_query("SELECT COUNT(message_id) as nbmail, MIN(message_id) as oldmail FROM mail_link WHERE player_id='$pid'");
$NbMsg = mysql_result($query, "nbmail");
//If the mailbox is full, delete the oldest message
if ($NbMsg > 2) {
$OldestMessage = mysql_result($query, "oldmail");
$Query = "DELETE FROM mail_link WHERE message_id = $OldestMessage";
sql_query($Query);
return 2;
}
return 1;
}
But this function doesn't works. I'm getting error saying that : Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/neomaster/ on line 18
(BTW , line 18 is the first mysql_result in this function.)