PHP: Update MySQL entry based on certain date

128 Views Asked by At

I have an entry in my database, and when a certain date hits I want to update the entry.

Here's an example:

+----+----------+-------------+---------+
| id |  title   |  exiryDate  |  status |
+----+----------+-------------+---------+
| 23 | my title | 10-Sep-2013 |  active |
+----+----------+-------------+---------+

My code is written in PHP and the idea is that when the date hits 10th September, the 'status' of the entry will update to expired instead of active.

How could I update the entry in DB based on date?

I suppose I could run a check on page load every time someone visits the page, but what if I want to update the entry without someone necessarily visiting the site or the web page?

1

There are 1 best solutions below

2
On BEST ANSWER

you'll need to create a cron job that checks the date and updates your db. It's pretty easy to do if you have a control panel from your web host.

Just create a PHP script that does what you want, then set the cron scheduler to run that script when you want.

Just create the PHP script with the code you want, and put this at the very top

#!/usr/bin/php -q
<?php
// put your script here

Save the file and CHMOD it to 755. After that you can set your cron job

Finding the cron manager on GoDaddy: http://answers.yahoo.com/question/index?qid=20120523092508AA2vOUU.