Portal Home > Knowledgebase > Articles Database > PHP - MySQL | auto send email & change field


PHP - MySQL | auto send email & change field




Posted by cn92, 08-07-2009, 09:01 AM
I am working on a new project and I need your help. We have a database, with the tables users & payments. In payments' table we have a field next_payment. I want XX days before the date in the field to send automatically an email to inform the user. AND If the user didn't pay until this date, to change automaticaly the status of the payment to unpayed. Nik.

Posted by mattle, 08-09-2009, 07:07 AM
Easy enough...what's the problem?

Posted by ChrisGeiger, 08-09-2009, 02:33 PM
Hopefully you are storing the dates as timestamps. Just use mktime(); =) and do mktime(0,0,0,0,$timeinDB-4,0); So its the date -4 days, if thats today, then do something.

Posted by m_php, 08-09-2009, 02:39 PM
well and for that to work fine, you would need to run the script daily. So I would suggest you setup a cron job.

Posted by mattle, 08-09-2009, 03:53 PM
Not necessary...MySQL does date comparisons: With DATETIME fields: With DATE fields: With int field using a UNIX style timestamp: Once you process the emails, you can use the same WHERE clause to UPDATE your payment status flag. ref: http://dev.mysql.com/doc/refman/5.0/...functions.html

Posted by cn92, 08-11-2009, 08:01 AM
I expected it more difficult... Ok, I will try it, the only step I worry about is the cron job, cause I have never done it before. I read a tut from my hoster and it seems to be easy. Thank you all for your help!

Posted by m_php, 08-11-2009, 08:25 AM
Which control panel does your host provide?

Posted by cn92, 08-11-2009, 08:44 AM
I use putty, it is ssh. I will use these to make the cron: export EDITOR=nano crontab -e m h dm m dw command In the tutorial are some examples..

Posted by okhud, 08-12-2009, 01:44 AM
If you're on a cpanel webhost, you can use the Cron Job option in cpanel to make things easier. All you'll need to do is setup the script to run the query (in a php file somewhere on your server) and direct the cron job to run it. Video, first google search result: http://www.2serveu.net/cpanel-tutori...ndardcron.html

Posted by mattle, 08-12-2009, 08:00 AM
Personally, I like his way better...what's wrong with learning how to really write a crontab?



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
question (Views: 517)
Are you making enough? (Views: 502)
Leaseweb VPS ? (Views: 536)