uwannadonkey Posted August 14, 2007 Share Posted August 14, 2007 im using a free host, and i need a cron for my website lets say i wanna add 5 energy, every 10 minutes, right how would i do it? in my php, i would have <?php db_connect then like mysql_query(update `users` SET energy= energy + (5); ?> would that work? and what should i write in my crontab? Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/ Share on other sites More sharing options...
btherl Posted August 14, 2007 Share Posted August 14, 2007 Here are some examples: http://en.wikipedia.org/wiki/Crontab#Examples In your case, something like: 0,10,20,30,40,50 * * * * /home/users/uwannadonkey/add_energy.php That will run at 0, 10,20,30,40 and 50 minutes past each hour, every hour Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/#findComment-323098 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Author Share Posted August 14, 2007 thanks for that post! what should i write in the php? any examples would be nice! i think curl isnt allowed by my free host Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/#findComment-323101 Share on other sites More sharing options...
btherl Posted August 14, 2007 Share Posted August 14, 2007 No curl should be fine. You can connect to the database directly from the php script called from cron. Much like the example in your original post. I can't give you a detailed example as I'm not too sure about your database setup. But it really is as simple as your example there. Just connect to the database and do the update. Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/#findComment-323242 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Author Share Posted August 14, 2007 still not solved.! all i have for crons is this: <?php $dbh=mysql_connect ("localhost", "donkey9_Admin", "xxx) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("donkey9_Game"); $sql2="UPDATE `users` SET energy=energy+10 WHERE energy < '$max_energy'"; if(mysql_query($sql2)) { echo $sql2; } ?> as my cron.php and my command line is wget http://donkeygame.1gig.biz/cron.php thats all i got, i know im doing something wrong, cuz if i go to my cron.php page, i dont gain any energy, so i doubt if cron runs it, ill get any? in ANY case, my crons arent working, i mean, im not getting any emails, and its been like 10 minutes Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/#findComment-323687 Share on other sites More sharing options...
rlindauer Posted August 14, 2007 Share Posted August 14, 2007 You are missing a closing quote there: <?php $dbh=mysql_connect ("localhost", "donkey9_Admin", "xxx) ?> Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/#findComment-323712 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Author Share Posted August 14, 2007 why would i close it? theres php script right after? Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/#findComment-323715 Share on other sites More sharing options...
trq Posted August 14, 2007 Share Posted August 14, 2007 Your missing the closing quote. Look... <?php $dbh=mysql_connect ("localhost", "donkey9_Admin", "xxx") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("donkey9_Game"); $sql2="UPDATE `users` SET energy=energy+10 WHERE energy < '$max_energy'"; if(mysql_query($sql2)) { echo $sql2; } ?> Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/#findComment-323719 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Author Share Posted August 14, 2007 ohhh psssht! thats right, my badddd umm that works now what about the command line? i have a free host, so i ono if wget or curl works? Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/#findComment-323720 Share on other sites More sharing options...
trq Posted August 14, 2007 Share Posted August 14, 2007 To run a cron every ten minutes via wget, you would use... */10 * * * * /usr/bin/wget http://donkeygame.1gig.biz/cron.php Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/#findComment-323722 Share on other sites More sharing options...
rlindauer Posted August 15, 2007 Share Posted August 15, 2007 why would i close it? theres php script right after? Because it is a syntax error. Link to comment https://forums.phpfreaks.com/topic/64771-solved-help-with-crons/#findComment-324145 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.