Creating subscription for website [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I would like some guidance in this. I am creating an update for a website that will allow a customer to subscribe to buy ebooks and have them sent out each month and automatically bill. I know how to use a sql database and PHP to keep track of members etc, but how do I make my website so that it will schedule things automatically at certain intervals. I tried Google searching, but maybe I didn't know how to phrase it.

With the help of Cron Job, on Linux hosts. Cron job can be used to automate your php script. So you write a script that does what you want and schedule it with Cron. Best approach is to write in the table when do you want Cron to run. For instance:
You have a column named "SendBook" with the date when the book should be sent. You set your php script to check if today is that date and if it is, send the book. For more help, visit this site
Code example:
$sevendays = date('Y-m-d', strtotime("+7 days")); // date is set to seven days from now
$sql= "INSERT INTO tablename (SendBook) VALUES ('$sevendays')"; // date is passed to the table
mysql_query($sql);
Than you create php script that checks if today is that date:
$checkdate = date("Y-m-d");
$sql = "SELECT SendBook AS '$comparedate' FROM tablename";
mysql_query($sql);
if ($checkdate == $comparedate){
// send email or whatever you want to do
}
Than simply make second script run whenever you want with Cron

Related

Send auto email on delay for each MySQL entry [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I currently have a MySQL database that sends an auto email each time a new record is entered. I need to also send a reminder email to the email address in each row 5 days after it is inserted. What is the best way to do this? Can I use a MySQL trigger or a cron job? I will likely need step by step instructions, if it isn't through PHP. I've done quite a bit of searching but can't find exactly what I'm looking for.
A cron job is what you need. The php file doing the cron needs to query the table for rows where the entry date is equal to 5 days ago. The mysql query is:
SELECT `email` FROM `entries` WHERE date(`entrytimestamp`) = date_sub(curdate(), INVERVAL 5 DAY);
Hopefully this gets you started in the right direction. You'll need to make sure that the php file cannot be called outside of cron, that cron only happens once a day, or maybe keep a separate table logging the emails where you would add a "NOT IN email_log" condition to make sure that you don't double up on emails to someone.

Autoupdate every day on database [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm having local MAMP server with phpmyadmin with three tables, users, booking and rooms. In table booking I have something like bookingFrom bookingTo columns that represents booking time. In rooms table I have something like isBooked aswell which is depending on time mostly.
I'd like to make something in my phpmyadmin that every day database will update itself and check if the room is occupied and if the bookingTo date will be before the day that currently is the database will automatically change isBooked from true to false.
My goal isn't the ready script to get, but the way to do it or any useful links as long as it is my training website for school project :)
you can't do such as think with phpmyadmin. You can try mysql scheduler if your version supports it.
Something like that should work...
CREATE EVENT myevent
ON SCHEDULE EVERY 1 DAY
DO
CALL check_book_status();
Please don't forget to create check_book_status function that updates field that you need.
Also, here more information...
http://dev.mysql.com/doc/refman/5.7/en/create-event.html
It might be possible to do this in the database directly, I'm not aware of any method that does this, but I'm sure it's possible (maybe not in mysql, but in some db-engine). However, can't you just do a simple PHP-run of an UPDATE-query at the start of the day (or, whenever), or even just run a cron-script at a specific time (half an hour after checkout, or something like that) and have it check the "end-date" in the database, and if it's before the current date/time, change the "occupied"-status?
You can make it without update status. Suffice calculate status when you show this info:
SELECT
IF(NOW() > bookingFrom AND NOW() < bookingTo, 1, 0) AS isBooked
/* other fields */
FROM booking
...

How can I time something in PHP? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to do on a script I`m working on that every month a part of the site resets.
Or a better example, Something like a Subscription, when you want to buy something and you need to renew it every month. How can I know its been a month?
In PHP you can't do regular cron jobs, and I will discourage you seriously from doing it with real cron jobs if you don't know what you're doing.
You can only register when you last executed that event and then check if it's been a month since then. This is a really simple sample cron:
<?php
$lastexecution = /*logic to know when you last executed.*/;
/* It's either a database or a file or something similar.
* I usually use a database table that contains the records when I
* last executed a cron
*/
if (time() > $lastexecution + (30 * 24 * 3600)) {
/*CRON LOGIC*/
}
You also should look into flock() or some similar locking mechanism to prevent the cron being triggered by two different users simultaneously.
Note: In your case, with a subscription, you could add a expires field to your database that would contain the date and time when the user's subscription needs to be renewed. If that date is in the past, you tell them

php form to email on scheduled time / date [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am going to do a basic form to email script, which is not a problem where you press send and the email goes. but what i want to do is i want to put additional fields in there for date and time and the email will go on that particular date/time. what is the best way to achieve this?
so for example at tuesday 13:30 i would like this script to run to send the email
send-mail.php?mail_id=4
and tuesday 13:45 send-mail.php?mail_id=5 where mail_id changes the mail recipients, content etc.
do i need to run another script every single minute to check in mysql if there is anything to be send? like
select * from mails where datetime = NOW() and if yes do the script? i dont think it is very good option as mysql will run 24/7 .
what are you recommendations
You could have a cron job that runs every 15 minutes and runs a sql statement like:
select * from mails where datetime <= NOW() AND isSent = 0
This would send all emails that are less then or equal to the current time. Make sure you update the record so you know it has been sent.

Background update in database using php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
We have a database table with created datetime and status flag. We would like to update the status flag to the next status if the created date time has elapsed by 30 minutes without any user intervention. How can we achieve this in php.
Create a php file that does this status change in the database and program to execute it every 30 minutes with cron (Linux) or Task Scheduler (Windows).
You have to think carefully about how you design and use your database. Sometimes things are made overly complicated when they don't need to. For instance, in this case you could use a 'datetime' in your table indicating the start time. Any PHP script can now check whether or not the start time started 30 minutes ago, only when this information is actually needed. No need for a flag, cron jobs, etc.

Categories