Edmhar Edmhar - 7 months ago 61
SQL Question

Change the value after expiration date PHP MYSQL

I'm beginner in PHP MySQL, I have system that after you register/add the customer information it will change the status after 30 days.

Scenario

In my add customer page, I have forms like Date Start, Date Expiration and Status.

Date Start - automatically set the date today

Expiration - Automatically set the Date Start + 30 days

Expiration2 - Automatically set the Expiration date + 90 days

Status - Status of the customer (if newly registered the status value will be

FRESH
if after 30days the status will change to
INACTIVE
if after 90days it will change to
DORMANT
.

This my code for
dateStart
and
dateExpired
,
dateExpired2
but I don't know how to code the
status
process.

$dateStart= Date('Y-m-d');
$dateExpired = date('Y-m-d', strtotime($dateStart. ' + 30 days'));
$dateExpired2 = date('Y-m-d', strtotime($dateExpired2. ' + 90days'));

echo '<input type="text" name= "dateStart" value="'. $dateStart.'"/>';
echo '<input type="text" name= "dateExpired" value="'. $dateExpired .'"/>';

Answer

If you run a script like this at a scheduled interval, it can automatically update your user's status':

$dateStart= date('Y-m-d');
$dateExpired = date('Y-m-d', strtotime($dateStart. ' + 30 days'));
$dateExpired2 = date('Y-m-d', strtotime($dateStart. ' + 90days'));

$status = "FRESH";

if(strtotime($dateStart)<strtotime('-30 days')){
   $status = "INACTIVE";
}

if(strtotime($dateStart)<strtotime('-90 days')){
   $status = "DORMANT";
}

//Run sql update query to set status

See here for sql update query

Comments