So, i'm working on grabbing a date of payment from a database, then add a year onto it as its expiry date. I want the user to know whether they are active or inactive when they log in.
However, everytime I login with someone who's payment hasn't expired yet, i get the you are an inactive member message. Can someone have a look and see where I am going wrong?
$paymentdate = strtotime($row[1]);
$paymentexpire = strtotime("+1 year", $paymentdate);
$currentdate = date('Y-m-d');
if($paymentdate != null && $paymentdate <= $currentdate && $currentdate < $paymentexpire){
$msg = $p->addContent("You are an active member<br>");
}
else{
$msg = $p->addContent("You are an inactive member<br>");
}
$paymentdate >= $paymentdate, the greater than part I mean... And in the second line $paymentdate is already a date which you are needlessly re-casting.strtotime($paymentdate)in$paymentexpire? You've already done that when setting$paymentdate!strtotime()returns an integer timestamp,date('Y-m-d')returns a string, and you cannot reliably compare the two. You should be usingtime()as in @Sam's example below as it returns an integer timestamp.