DELETE FROM banned_users
WHERE datetime < (NOW() - INTERVAL '$ban' MINUTE)
AND ban_length != 'INF';
INF is of course a perm ban, but intervals are as follows
60 - 1 hour
and
1440 - 24 hours
However it seems as though this query (which is run from PHP at the top of page load) is deleting all items that aren't 'INF' with a minute, not immediately but from what I can tell within a minute.
Why on earth is this happening? No wonder I was having problems with repeat offenders!
$ban = $row['ban_length'];
db:
CREATE TABLE IF NOT EXISTS `banned_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` varchar(200) NOT NULL,
`username` varchar(22) NOT NULL,
`ban_length` varchar(200) NOT NULL,
`reason` text NOT NULL,
`datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `ip` (`ip`)
)
echo the query
DELETE FROM banned_users
WHERE datetime < (NOW() - INTERVAL 60 MINUTE)
AND ban_length != 'INF';
Also, here is the PHP code
$result = mysql_query("SELECT * FROM banned_users WHERE ip = '$ip'")or die(mysql_error());
$is_banned = FALSE;
while($row = mysql_fetch_assoc($result)) {
$ban = $row['ban_length'];
$is_banned = TRUE;
$reason = $row['reason'];
mysql_query("
DELETE FROM banned_users
WHERE datetime < (NOW() - INTERVAL $ban MINUTE)
AND ban_length != 'INF';")or die(mysql_error());
}
if($is_banned) {
echo "banned";
}