hi,

my application i have built which runs on php/mysql i now need a way to have it insert a value into a table every set date.

so, on the isnert form just now they would enter the amount of money the company would receive and which date they were paid for history and tracking.

however i now need a way to have it insert say 1.00 every month on a date specified, so the 1st of every month it would insert into the table so if the get 10 people paying this they get 10 every month.

not sure how this would work if at all and they woudl also need the ability to then stop this, so a stop button in the application which would stop any further payments being inserted.

any thoughts on how this could work? they will never have root access to the database so needs to be done in a form on the site which would then do all the inserts every month.

thanks for your help

Recommended Answers

All 8 Replies

I'm not sure to understand what you asking for but if you want an automatic and general execution maybe you can use something like:

# $stop: get value from db or file for this action
if(date('d') == '01' && $stop == false)
{
   # execute insert query
}

And run it with crontab.

thanks, i have never ran a job using cron before however i found this script while looking around:

*/10 * * * * /usr/bin/wget -q -O temp.txt http://www.domain.com/myscript.php

would i just put your script in the myscript.php page obviously modified a bit and set this to run using cron?

thanks again

if you are making the script and have it on your server you can run it directly

*/10 * * * *  php-f myscript.php &> /dev/null

or usally where the script is located

*/10 * * * *  php-f /var/www/html/myscript.php &> /dev/null

that /dev ending thing stops it from emailing the server it can get annoying really quick
if your going to run it ever 10 seconds

if you want the script to run every first of the month

* * 1 * *  php-f /var/www/html/myscript.php &> /dev/null

those * in the cron mean
|Minute|Hour|Day of Month|Month|Day of Week|

thanks that was a great help.

really good.

now just need to have query which i guess will loop through the query as there could be 100 inserts needing to take plase based on a query outcome.

function connectdb()
    {   
        $h = "host";
        $u = "username";
        $p = "password";
        $d = "database";
      $link = mysql_connect ($h, $u, $p) or die ("Could not connect to database, try again later");
mysql_select_db($d,$link);
    }
	
	

		 	connectdb(); 	
 for ( $counter = 0 ; $counter <= 100; $counter += 1) {		 	
$query = "INSERT INTO table_name (column1, column2, column3)VALUES (value1, value2, value3)"; 
$result = mysql_query($query) or die(mysql_error());
 }

you can see the 100 ti be a variable then set how many times you want to look and if your data is in a array you can use the counter to go up on digit

thanks again for the help that could be what i am looking for.

so the:

for ( $counter = 0 ; $counter <= 100; $counter += 1)

is the looper?

for ( $counter = 0 ; $counter <= 100; $counter += 1) {  


looop  me :-)


}

must have those brackets you put anything you want to loop between the {}
the other thing before it has three parts starting point ; how many times to do it ; and by how many to count up by

what are you trying to do i can maybe steer you or maybe give u a better whole example ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.