In a MySQL database I have a column called 'mem_expire' which contains date values in the format of '24/01/2010'.
I am trying to use some conditional statements to delete all records where the expiry date is less than a pre-set time variable. Here is my code but i'm not sure if i am going about it the right way OR whether you can use PHP functions in a SQL query?
Code: / Delete Expired Members
$oneyear = time() - (52 * 7 * 24 * 60 * 60);
$fiveyears = time() - (5 * 52 * 7 * 24 * 60 * 60);
$tenyears = time() - (10 * 52 * 7 * 24 * 60 * 60);
if (isset($_POST['delete'])) {
$delete = mysqli_real_escape_string($connection, $_POST['deleteold']);
if ($delete == '1') {
$deletequery = "DELETE FROM members WHERE" . strtotime('mem_expire') ." < $oneyear";
} elseif ($delete == '5') {
$deletequery = "DELETE FROM members WHERE" . strtotime('mem_expire') . "< $fiveyears";
} elseif ($delete == '10') {
$deletequery = "DELETE FROM members WHERE" . strtotime('mem_expire') . "< $tenyears";
}
$deleteresult = mysqli_query($connection, $deletequery);
}
You can see what i am trying to do but i'm not going about it the right way, can someone point me in the right direction please. Any help is good help :)