Need help with cron - database coding. I'm trying to set up a cron on a game site of mine. The game updates the energy, health and income of the user. One of them is working, updating the user's health and energy, but somehow the income doesn't update. I used the advanced unix with the following cron code: env php -q /home/USERNAME/public_html/fightclub/cron/usercashcron.php Here's the usercashcron.php file <?php include "../includes/config.php"; //==================================== // Get User Income //==================================== function get_income( $id ) { $res = query("SELECT * FROM `cu_assest_list` WHERE `aid`=$id"); while( $row = mysql_fetch_array($res) ) { $income = $row[aincome]; } return $income; } //==================================== // Update User Cash //==================================== function update_cash( $u ) { $total_cash = 0; $res = query("SELECT * FROM `cu_assest_log` WHERE `userid`=$u"); while( $row = mysql_fetch_array($res) ) { $total_cash = $total_cash + ( $row[quantity] * get_income($row[aid]) ); } $res = query("UPDATE `cu_users` SET `ucash`=(`ucash`+ $total_cash) WHERE `userid`=$u"); } ?>
Make sure all your include files are specified with absolute paths as cron will not run the script in the directory it resides.
joep's probably got it, looks like it's probably your include files. Cron needs the full path: /path/to/config.php
I had this problem execute it as cURL instead of PHP and it worked for me mine looks like: curl /home/directory/to/html/system/file.php
Thanks for all the replies. I had someone else do it. Just in case anyone's interested in the solution they came up with... The programmer created another file filet.php which has the following code: <?php include "includes/config.php"; //==================================== // Update User Cash //==================================== $res3 = query("SELECT cu_assest_log.userid, cu_assest_log.aid, cu_assest_log.quantity, cu_assest_list.aincome FROM `cu_assest_log` LEFT JOIN cu_assest_list ON cu_assest_log.aid=cu_assest_list.aid LEFT JOIN cu_users ON cu_assest_log.userid=cu_users.userid"); while( $row = mysql_fetch_array($res3) ) { $u=$row['userid']; $aid=$row['aid']; $qty=$row['quantity']; $income=$row['aincome']; $total_cash = 0; $total_cash = $total_cash + ( $qty * $income ); $res = query("UPDATE `cu_users` SET `ucash`=(`ucash`+ $total_cash) WHERE `userid`=$u"); } ?> For the cron job in advanced unix, it looks like this: ***** env php -q /home/USERNAME/public_html/SUBDIR/cron/usercashcron.php */5 **** env php -q /home/USERNAME/public_html/SUBDIR/cron/usercron.php 0**** env php -q /home/USERNAME/public_html/SUBDIR/filet.php */5 apparently stands for 5 minutes, i.e., the game upgrades the health function every 5 minutes.