Well I'd suggest you use an cronjob/script for this.
On some hosts they have a function available for you to just set up a cronjob easily. Otherwise you could check up how to do it yourself - if needed.
How to write a Cron Job to execute simple php script? How to create cron job using PHP?
Edit; Also like someone commented, use mysqli rather than mysql.