I am writing password recovery code that uses a token and a date stored in date("Y-m-d H:i:s") format e.g. 2012-09-06 18:59:53. I use the code below to check if the token key for a user id exists:
$sql = mysql_query("SELECT * FROM `recoveryemails` WHERE `UserID` = '$uid' and `Key` = '$key' and `expDate` >= '$curDate'");
I need to add another condition after retrieving the expDate to check whether it’s older than 3 days, using PHP. Can anyone help me out with that PHP code?
It’s a lot easier in MySQL:
WHERE ... AND expdate >= DATE_SUB(NOW(),INTERVAL 3 DAY)But if you insist on doing it in PHP, you will need: