I’m trying to get a mysql PDO statement to select all of the failed logins that have occurred in the last day. My table has 4 columns…id (just auto increments to make distinct entries), ip (char 15), failed (boolean), firstattempt (timestamp). When I add firstattempt>=(CURDATE() – INTERVAL 3 DAY) in, it starts return false. Without that in the WHERE clause, it does return the number of lines. Any ideas?
function logip()
{
global $db;
global $user;
$ip = $_SERVER['REMOTE_ADDR'];
var_dump($ip);
$sql=$db->prepare('SELECT COUNT(failed) FROM logins WHERE firstattempt>=(CURDATE() - INTERVAL 3 DAY), ip=:ip');
$sql->execute(array(':ip'=>$ip));
$num=$sql->fetchColumn();
//$row=$sql->fetch();
var_dump($num);
$sql=$db->prepare('INSERT INTO logins (ip, failed, firstattempt) VALUES (:ip, :failed, :firstattempt)');
if ($user->authenticated())
$sql->execute(array(':ip'=>$ip, ':failed'=>false, ':firstattempt'=>time()));
else
$sql->execute(array(':ip'=>$ip, ':failed'=>true, ':firstattempt'=>time()));
}
Use DATE_SUB function.
There were some errors in your sql,
,. I think it should beAND