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"); } ?>
u need to instantiate the functions and provide userid <?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]) ); } return $total_cash; } $u = 'youruserIDhere'; $total_cash = update_cash($u); $res = query("UPDATE `cu_users` SET `ucash`=(`ucash`+ $total_cash) WHERE `userid`=$u"); ?> PHP:
Maybe there's some error with the cron command. In the past I tried php -l to call a .php file, but it does not work as expected. Then I used lynx its URL and all works Or, you can try a external cron jobs (onlinecronjob.com www.setcronjob.com) to call your URL instead of lynx (if your host doesn't have lynx)