...

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



2y2d
08-12-2007, 04: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
(12:15pm)
points = 2
(12:30pm)
points = 3
(.... 2:00pm)
points = 9
And so on

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

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

2y2d
08-12-2007, 08: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

Inigoesdr
08-12-2007, 08: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.

2y2d
08-12-2007, 08: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 :)

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

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

Contents of test.pl.


<?php
$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'
. ' ';
?>

Inigoesdr
08-12-2007, 09: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?)

2y2d
08-12-2007, 09: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"); '

:S

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

Inigoesdr
08-12-2007, 10: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.

2y2d
08-14-2007, 01: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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum