Edmhar
Edmhar

Reputation: 650

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 .'"/>';

Upvotes: 2

Views: 4653

Answers (2)

Niranjan N Raju
Niranjan N Raju

Reputation: 11987

Trigger a cron job.

  • You should write code in a .php file, to do what you require(change status if date has exceeded 30 days or 90 days)
  • You should make sure that, you file doesn't have any session related to it.

I have added following images , refer them

enter image description here

I have added a cron which runs once in a day. and in your server, it looks like this.

enter image description here

Upvotes: 3

tkav
tkav

Reputation: 94

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

Upvotes: 2

Related Questions