View Full Version : Making changes to a database on a chosen time

08-12-2007, 05:07 PM
Hi i was wondering if there was a guide to making something change in a database on a certain time of the day, What i want to happen is that a user will start with 1 of something but every 15mins i want this to add 1 to what the user already has E.g. :
Lets say the time was 12:00pm
points = 1
and then at every 15 min intervals it would increase by 1
points = 2
points = 3
(.... 2:00pm)
points = 9
And so on

Any links to guides on how to do this would be helpful :)

08-12-2007, 06:00 PM
Google for "cron job"

08-12-2007, 09:43 PM
Is there another way i can make the points increment every 15 mins, the cron job isnt working it keeps saying " permission denied " so i tryed changing chmod but still didnt work

08-12-2007, 09:46 PM
As an alternative to a cron job(which should the the first choice), when the user logs in you could calculate the time since the last login and update the database accordingly.

08-12-2007, 09:57 PM
i do think that a cron job would be the best, Because im expecting alot of users and each user is going to be able to see another users points. ill post what i did (when making a cron job) and what it tells me maybe someone can help me get it right lol

EDIT Ok sorry lol i seem to have missed something in the address when making the cron ill tell you if it works this time :)

08-12-2007, 10:16 PM
Heres what i got when it should have runned test.pl.

nice: /home/sites/*****/******/test.pl.: Permission denied

Contents of test.pl.

$host="localhost"; // Host name
$username="*****"; // Mysql username
$password="****"; // Mysql password
$db_name="*****"; // Database name
$tbl_name="MainT"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = 'UPDATE `MainT` SET `Points` = 'Points + 1'
. ' ';

08-12-2007, 10:27 PM
Well, the filename is wrong, you have a syntax error(see below), and the permissions of the file are wrong(what are they?). Does your user own the file, and have access to run cron jobs?

$sql = 'UPDATE `MainT` SET `Points` = `Points` + 1'; // Might need a WHERE clause depending on MySQL versions(I think?)

08-12-2007, 10:37 PM
Renamed the test.pl. to test.php and ive set the permissions to 755 i also changed the query lol ill edit this post when i know if it works or not

Edit ( what i got )=
/home/sites/******/public_html/test.php: line 1: ?php: No such file or directory/home/sites/****/public_html/test.php: line 2: =localhost: command not found/home/sites/*****/public_html/test.php: line 2: //: is a directory/home/sites/****/public_html/test.php: line 3: =*****: command not found/home/sites/*****/public_html/test.php: line 3: //: is a directory/home/sites/*****/public_html/test.php: line 4: =******: command not found/home/sites******/public_html/test.php: line 4: //: is a directory/home/sites/****/public_html/test.php: line 5: =*****: command not found/home/sites/*****/public_html/test.php: line 5: //: is a directory/home/sites/*****/public_html/test.php: line 6: =MainT: command not found/home/sites/******/public_html/test.php: line 6: //: is a directory/home/sites/*****/public_html/test.php: line 8: syntax error near unexpected token `"$host",'/home/sites/*****/public_html/test.php: line 8: `mysql_connect("$host", "$username", "$password")or die("cannot connect"); '


08-12-2007, 10:55 PM
i dont think its going to let me use php in the cron job :s

08-12-2007, 11:09 PM
It doesn't look like php is being called. Check out this link (http://www.htmlcenter.com/tutorials/tutorials.cfm/155/PHP/) for some information on how to setup the cron job. Or use a search engine to find some more examples. You should move the file out of the public_html folder so it can't be accessed by everyone going to your site, too.

08-14-2007, 02:54 PM
still doesnt seem to work ive got it to open the correct file and all i dont get the permissions denied anymore what i do get now is that the file to open that has the php in it doesnt exist but it is there and the path i made absolute lol ill just have to keep trying lol once i get sorted and running ill post how i did it in the tutorials so that people know how to go about it