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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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) ?> Quote Link to comment 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? Quote Link to comment 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; } ?> Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.