Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-12-2007, 04:07 PM   PM User | #1
2y2d
New Coder

 
Join Date: Aug 2007
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
2y2d is an unknown quantity at this point
Making changes to a database on a chosen time

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
2y2d is offline   Reply With Quote
Old 08-12-2007, 05:00 PM   PM User | #2
PappaJohn
Senior Coder

 
Join Date: Apr 2007
Location: Quakertown PA USA
Posts: 1,028
Thanks: 1
Thanked 125 Times in 123 Posts
PappaJohn will become famous soon enough
Google for "cron job"
PappaJohn is offline   Reply With Quote
Old 08-12-2007, 08:43 PM   PM User | #3
2y2d
New Coder

 
Join Date: Aug 2007
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
2y2d is an unknown quantity at this point
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
2y2d is offline   Reply With Quote
Old 08-12-2007, 08:46 PM   PM User | #4
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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.
Inigoesdr is offline   Reply With Quote
Old 08-12-2007, 08:57 PM   PM User | #5
2y2d
New Coder

 
Join Date: Aug 2007
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
2y2d is an unknown quantity at this point
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

Last edited by 2y2d; 08-12-2007 at 09:10 PM..
2y2d is offline   Reply With Quote
Old 08-12-2007, 09:16 PM   PM User | #6
2y2d
New Coder

 
Join Date: Aug 2007
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
2y2d is an unknown quantity at this point
Heres what i got when it should have runned test.pl.

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

Contents of test.pl.
PHP Code:
<?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
        . ' 
;
?>
2y2d is offline   Reply With Quote
Old 08-12-2007, 09:27 PM   PM User | #7
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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?
PHP Code:
$sql 'UPDATE `MainT` SET `Points` =  `Points` + 1'// Might need a WHERE clause depending on MySQL versions(I think?) 
Inigoesdr is offline   Reply With Quote
Old 08-12-2007, 09:37 PM   PM User | #8
2y2d
New Coder

 
Join Date: Aug 2007
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
2y2d is an unknown quantity at this point
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

Last edited by 2y2d; 08-12-2007 at 09:42 PM..
2y2d is offline   Reply With Quote
Old 08-12-2007, 09:55 PM   PM User | #9
2y2d
New Coder

 
Join Date: Aug 2007
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
2y2d is an unknown quantity at this point
i dont think its going to let me use php in the cron job :s
2y2d is offline   Reply With Quote
Old 08-12-2007, 10:09 PM   PM User | #10
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
It doesn't look like php is being called. Check out this link 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.
Inigoesdr is offline   Reply With Quote
Old 08-14-2007, 01:54 PM   PM User | #11
2y2d
New Coder

 
Join Date: Aug 2007
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
2y2d is an unknown quantity at this point
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
2y2d is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:26 PM.


Advertisement
Log in to turn off these ads.