-BRAIDZ- Posted August 28, 2015 Share Posted August 28, 2015 Okay so my daily cron updates twice for some reason and times out.. Even when manually run it will time out.. Is anyone able go tell me why please? The mysql_real_escape_string's do need removing I know that, but there's some.parts of the cron I don't want to touch with the mres just incase I stuff it up. Any suggestions would be great please. Or what I can do with the mres? <?php $dbhost = "localhost"; $dbuser = "blah"; $dbpass = "nottellingyou"; $dbbase = "mygameduh"; $cron_are_so_cool = "trick_is_da_bomb"; $db = "mysql_tut"; $con = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbbase); if ($_GET['code_to_run'] < 0) { die("<center><font color=red>Fatal error!</font> <br/><blink>IP logged as {$_SERVER['REMOTE_ADDR']}</blink></center>"); } else { /*----------------------------------Start cron minutes--------------------------*/ mysql_query("UPDATE `members` SET `my_mailban` = `my_mailban` - '1' WHERE `my_mailban` >= '1'") or die(mysql_error()); mysql_query("UPDATE `members` SET `my_forumban` = `my_forumban` - '1' WHERE `my_forumban` >= '1'") or die(mysql_error()); mysql_query("UPDATE `none_agressive` SET `na_days` = `na_days` - '1' WHERE `na_days` >= '1'") or die(mysql_error()); mysql_query("DELETE FROM `none_agressive` WHERE `na_days` <= '0'") or die(mysql_error()); mysql_query("UPDATE `city_shop_dogs` SET `csd_daysold` = `csd_daysold` + '1'") or die(mysql_error()); mysql_query("UPDATE `members_dogs` SET `md_daysold` = `md_daysold` + '1'") or die(mysql_error()); $newones = rand(1, 15); $morf = array( 1 => 'male', 2 => 'female' ); for ($i = 1; $i <= $newones; $i++) { $q_ry = array(); $q_ry = "INSERT INTO `city_shop_dogs` VALUES('NULL', '" . rand(1, 8) . "', '" . $morf[rand(1, 2)] . "', 0)"; mysql_query($q_ry) or die(mysql_error()); } $withjob = array(); $wj = array(); $q_ry = array(); $q_ry = "SELECT me.my_job,me.my_job_rank,me.playerid, sjr.*,m.my_level FROM `members_extra` me INNER JOIN `system_job_ranks` AS sjr ON me.my_job_rank = sjr.r_ID INNER JOIN `members` AS m ON me.playerid = m.playerid WHERE me.my_job > '0'"; $withjob = array(); $withjob = mysql_query($q_ry) or die(mysql_error()); $wj = array(); while ($wj = mysql_fetch_array($withjob)) { $q_ry = array(); $q_ry = "UPDATE `memberstats` SET `my_labor` = `my_labor` + '" . mysql_real_escape_string($wj['r_MANUALGAIN']) . "', `my_intelligence` = `my_intelligence` + '" . mysql_real_escape_string($wj['r_INTELGAIN']) . "', `my_endurance` = `my_endurance` + '" . mysql_real_escape_string($wj['r_ENDURGAIN']) . "' WHERE `playerid` = '" . mysql_real_escape_string($wj['playerid']) . "'"; mysql_query($q_ry) or die(mysql_error()); $job = array( 1 => 'armypoints', 2 => 'grocpoints', 3 => 'casipoints', 4 => 'medipoints', 5 => 'educpoints', 6 => 'lawpoints' ); $wj['r_POINTS'] *= $wj['my_level']; $q_ry = array(); $q_ry = "UPDATE `members_extra` SET " . $job[$wj['my_job']] . " = " . $job[$wj['my_job']] . " + '" . mysql_real_escape_string($wj['r_POINTS']) . "' WHERE `playerid` = '" . mysql_real_escape_string($wj['playerid']) . "'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "UPDATE `members` SET `wallet` = `wallet` + '" . mysql_real_escape_string($wj['r_WAGES']) . "' WHERE `playerid` = '" . mysql_real_escape_string($wj['playerid']) . "'"; mysql_query($q_ry) or die(mysql_error()); } function remove_staff($id) { $q_ry = array(); $q_ry = "SELECT `p_maids`,`p_butler`,`p_guard`,`p_doctor`,`p_pilot` FROM `members_properties` WHERE `p_id` = '" . mysql_real_escape_string($id) . "'"; $uptime = array(); $uptime = mysql_query($q_ry); $ut = array(); $ut = mysql_fetch_array($uptime); $happloss = 0; if ($ut['p_maids'] != '0') { $q_ry = array(); $q_ry = "SELECT `ps_name` FROM `property_staff` WHERE `ps_id` = '" . mysql_real_escape_string($ut['p_maids']) . "'"; $wichmaids = array(); $wichmaids = mysql_query($q_ry); $wms = mysql_fetch_array($wichmaids); $wms = array(); if ($wms['ps_name'] == '5x Maid Service') { $happloss += 100; } if ($wms['ps_name'] == '3x Maid Service') { $happloss += 85; } if ($wms['ps_name'] == '2x Maid Service') { $happloss += 75; } if ($wms['ps_name'] == 'Maid Service') { $happloss += 50; } } if ($ut['p_butler'] != '0') { $q_ry = array(); $q_ry = "SELECT `ps_name` FROM `property_staff` WHERE `ps_id` = '" . mysql_real_escape_string($ut['p_butler']) . "'"; $wichbutlers = array(); $wichbutlers = mysql_query($q_ry); $wmb = mysql_fetch_array($wichbutlers); $wmb = array(); if ($wmb['ps_name'] == '3x Butler Service') { $happloss += 125; } if ($wmb['ps_name'] == '2x Butler Service') { $happloss += 100; } if ($wmb['ps_name'] == 'Butler Service') { $happloss += 75; } } if ($ut['p_guard'] != '0') { $q_ry = array(); $q_ry = "SELECT `ps_name` FROM `property_staff` WHERE `ps_id`='" . mysql_real_escape_string($ut['p_guard']) . "'"; $wichguards = array(); $wichguards = mysql_query($q_ry); $wmg = mysql_fetch_array($wichguards); $wmg = array(); if ($wmg['ps_name'] == '10x Guard Service') { $happloss += 500; } if ($wmg['ps_name'] == '5x Guard Service') { $happloss += 300; } if ($wmg['ps_name'] == '3x Guard Service') { $happloss += 200; } if ($wmg['ps_name'] == '2x Guard Service') { $happloss += 150; } if ($wmg['ps_name'] == 'Guard Service') { $happloss += 100; } } if ($ut['p_doctor'] != '0') { $happloss += 25; } if ($ut['p_pilot'] != '0') { $happloss += 50; } $q_ry = array(); $q_ry = "UPDATE `members_properties` SET `p_happy` = `p_happy` - '" . mysql_real_escape_string($happloss) . "', `p_maids` = '0', `p_butler` = '0', `p_guard` = '0', `p_doctor` = '0', `p_pilot` = '0', `p_priceofstaff` = '0', `p_daysofstaff` = '0' WHERE `p_id` = '" . mysql_real_escape_string($id) . "'"; mysql_query($q_ry); $q_ry = array(); $q_ry = "UPDATE `members` SET `my_maxhappy` = `my_maxhappy` - '" . mysql_real_escape_string($happloss) . "' WHERE `my_property` = '" . mysql_real_escape_string($id) . "'"; mysql_query($q_ry); } function in_event($player, $text) { $player = abs(intval($player)); $text = stripslashes($text); mysql_query("INSERT INTO `member_events` VALUES('NULL', '" . mysql_real_escape_string($player) . "', '" . mysql_real_escape_string($text) . "', unix_timestamp(), '0')") or die(mysql_error()); mysql_query("UPDATE `city_statistic` SET `cs_value` = `cs_value` + '1' WHERE `cs_id` = '1'") or die(mysql_error()); } function stock_credit($id, $credit) { $q_ry = array(); $q_ry = "UPDATE `stock_market` SET `s_profit` = `s_profit` + '" . mysql_real_escape_string($credit) . "', `s_losses` = `s_losses` - '" . mysql_real_escape_string($credit) . "' WHERE `s_id` = '" . mysql_real_escape_string($id) . "'"; mysql_query($q_ry); $q_ry = array(); $q_ry = "UPDATE `stock_market` SET `s_profit` = '0' WHERE `s_profit` <= '0'"; mysql_query($q_ry); $q_ry = array(); $q_ry = "UPDATE `stock_market` SET `s_losses` = '0' WHERE `s_losses` <= '0'"; mysql_query($q_ry); } mysql_query("UPDATE `members_properties` SET `p_ltime` = `p_ltime` - '1' WHERE `p_leasedto` > '0'"); mysql_query("UPDATE `members_properties` SET `p_daysofstaff` = `p_daysofstaff` + '1' WHERE `p_priceofstaff` > '0'"); //Check for expired rentings $q_ry = array(); $q_ry = "SELECT * FROM `members_properties` mp LEFT JOIN `properties` h ON mp.p_property = h.house_id WHERE mp.p_leasedto != '0' AND mp.p_ltime = '0'"; $uptime = array(); $uptime = mysql_query($q_ry); while ($ut = mysql_fetch_array($uptime)) { $message1 = "The rent period for your " . htmlentities($ut['house_name']) . " has now finished, The " . htmlentities($ut['house_name']) . " has been returned to you."; $q_ry = array(); $q_ry = "INSERT INTO `member_events` VALUES ('NULL', '" . mysql_real_escape_string($ut['p_playerid']) . "', '" . mysql_real_escape_string($message1) . "', unix_timestamp(), '0')"; mysql_query($q_ry); $message2 = "The rent period for the " . htmlentities($ut['house_name']) . " has now finished, The " . htmlentities($ut['house_name']) . " has been returned to its owner."; $q_ry = array(); $q_ry = "INSERT INTO `member_events` VALUES ('NULL', '" . mysql_real_escape_string($ut['p_leasedto']) . "', '" . mysql_real_escape_string($message2) . "', unix_timestamp(), '0')"; mysql_query($q_ry); $q_ry = array(); $q_ry = "SELECT `playerid` FROM `members` WHERE `my_property` = '" . mysql_real_escape_string($ut['p_id']) . "'"; $mys = array(); $mys = mysql_query($q_ry); if (mysql_num_rows($mys)) { $my = array(); while ($my = mysql_fetch_array($mys)) { $q_ry = array(); $q_ry = "SELECT `p_id` FROM `members_properties` WHERE `p_playerid` = '" . mysql_real_escape_string($my['playerid']) . "' AND `p_property` = '1'"; $myshack = array(); $myshack = mysql_query($q_ry); $msh = array(); $msh = mysql_fetch_array($myshack); $q_ry = array(); $q_ry = "UPDATE `members` SET `my_property` = '" . mysql_real_escape_string($msh['p_id']) . "', `my_happy` = '100', `my_maxhappy` = '100' WHERE `playerid` = '" . mysql_real_escape_string($my['playerid']) . "'"; mysql_query($q_ry); } } remove_staff($ut['p_id']); $q_ry = array(); $q_ry = "UPDATE `members_properties` SET `p_leasedto` = '0', `p_ltime` = '0' WHERE `p_id` = '" . mysql_real_escape_string($ut['p_id']) . "'"; mysql_query($q_ry); } //Check for expired rentings //Charge daily upkeep $q_ry = array(); $q_ry = "SELECT * FROM `members_properties` mp LEFT JOIN `properties` h ON mp.p_property = h.house_id WHERE mp.p_property != '1'"; $upprops = array(); $upprops = mysql_query($q_ry); $up = array(); while ($up = mysql_fetch_array($upprops)) { $total = ($up['p_priceofstaff'] + $up['house_tax']); if ($up['p_leasedto'] != '0') { //Check money of tenant $q_ry = array(); $q_ry = "SELECT `playerid` FROM `members` WHERE `playerid` = '" . mysql_real_escape_string($up['p_leasedto']) . "' AND `wallet` <= '-" . mysql_real_escape_string($total) . "'"; $myc = array(); $myc = mysql_query($q_ry); if ($up['p_priceofstaff']) { stock_credit(5, 1); if (mysql_num_rows($myc)) { remove_staff($up['p_id']); $message3 = "You did not have enough to pay your staff for today, They have packed up and left!"; in_event($up['p_leasedto'], $message3); } } $q_ry = array(); $q_ry = "UPDATE `members` SET `wallet` = `wallet` - '" . mysql_real_escape_string($total) . "' WHERE `playerid` = '" . mysql_real_escape_string($up['p_leasedto']) . "'"; } else { //Check money of member $q_ry = array(); $q_ry = "SELECT `wallet` FROM `members` WHERE `playerid` = '" . mysql_real_escape_string($up['p_playerid']) . "' AND `wallet` <= '-" . mysql_real_escape_string($total) . "'"; $myc = array(); $myc = mysql_query($q_ry); if ($up['p_priceofstaff']) { stock_credit(5, 1); if (mysql_num_rows($myc)) { remove_staff($up['p_id']); $message3 = "You did not have enough to pay your staff for today, They have packed up and left!"; in_event($up['p_playerid'], $message3); } } $q_ry = array(); $q_ry = "UPDATE `members` SET `wallet` = `wallet` - '" . mysql_real_escape_string($total) . "' WHERE `playerid` = '" . mysql_real_escape_string($up['p_playerid']) . "'"; } mysql_query($q_ry); } //Charge daily upkeep /*-----------------------------------End cron minutes---------------------------*/ function award_check($user, $number, $award) { $q_ry = array(); $q_ry = "SELECT `ma_id`,`ma_tier` FROM `members_awards` WHERE `ma_playerid` = '" . mysql_real_escape_string($user) . "' AND `ma_award` = '" . mysql_real_escape_string($award) . "'"; $got_award = array(); $got_award = mysql_query($q_ry) or die(mysql_error()); if (mysql_num_rows($got_award)) { $ga = array(); $ga = mysql_fetch_array($got_award); if ($ga['ma_tier'] >= $number) { //Got it } else { $q_ry = array(); $q_ry = "UPDATE `members_awards` SET `ma_tier` = '" . mysql_real_escape_string($number) . "', `ma_viewed` = '0', `ma_time` = unix_timestamp() WHERE `ma_id` = '" . mysql_real_escape_string($ga['ma_id']) . "'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "UPDATE `members` SET `my_merits` = `my_merits` + '1' WHERE `playerid` = '" . mysql_real_escape_string($user) . "'"; mysql_query($q_ry) or die(mysql_error()); } } else { $q_ry = array(); $q_ry = "INSERT INTO `members_awards` VALUES ('NULL', '" . mysql_real_escape_string($award) . "', '" . mysql_real_escape_string($number) . "', '" . mysql_real_escape_string($user) . "', '0', unix_timestamp())"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "UPDATE `members` SET `my_merits` = `my_merits` + '1' WHERE `playerid` = '" . mysql_real_escape_string($user) . "'"; mysql_query($q_ry) or die(mysql_error()); } } $q_ry = array(); $q_ry = "SELECT * FROM `award_checks` ac LEFT JOIN `awards` a ON ac.ac_award_id = a.a_id"; $award_checks = array(); $award_checks = mysql_query($q_ry) or die(mysql_error()); while ($aw = mysql_fetch_array($award_checks)) { $q_ry = array(); $q_ry = "SELECT " . $aw['ac_identify'] . "," . $aw['ac_what'] . " FROM " . $aw['ac_table'] . " WHERE " . $aw['ac_what'] . " >= '" . $aw['ac_amount'] . "'"; $thisaward = array(); $thisaward = mysql_query($q_ry) or die(mysql_error()); if (mysql_num_rows($thisaward)) { while ($ta = mysql_fetch_array($thisaward)) { award_check($ta[$aw['ac_identify']], $aw['ac_number'], $aw['ac_award_id']); } } } mysql_query("UPDATE `members` SET `my_dondays` = `my_dondays` - '1' WHERE `my_dondays` > '0'"); mysql_query("UPDATE `members` SET `my_maxenergy` = '100' WHERE `my_dondays` <= '0'"); mysql_query("UPDATE `members` SET `my_partner_days` = `my_partner_days` + '1' WHERE `my_partner` > '0'"); mysql_query("UPDATE `members` SET `brew` = '0'"); mysql_query("UPDATE `members_extra` SET `my_daysold` = `my_daysold` + '1'"); mysql_query("UPDATE `members_extra` SET `my_ctokens` = `my_ctokens_daily`,`my_cstreak` = '0'"); mysql_query("UPDATE `members_extra` SET `energy_refill` = '0'"); $q_ry = array(); $q_ry = "SELECT `playerid` FROM `members` WHERE `my_faction` > '0'"; $facdays = array(); $facdays = mysql_query($q_ry) or die(mysql_error()); $fd = array(); $q_ry = array(); while ($fd = mysql_fetch_array($facdays)) { $q_ry = "UPDATE `members_extra` SET `my_faction_days` = `my_faction_days` + '1' WHERE `playerid` = '" . mysql_real_escape_string($fd['playerid']) . "'"; mysql_query($q_ry) or die(mysql_error()); } $q_ry = array(); $q_ry = "DELETE FROM `votes_count` WHERE `vc_site` = 'apex' || `vc_site` = 'ultra'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "SELECT * FROM `stock_holdings` WHERE `sh_saletime` > '0' AND (`sh_saletime`+1036800) <= '" . (time()) . "' AND `sh_playerid` != '3'"; $validstocks = array(); $validstocks = mysql_query($q_ry) or die(mysql_error()); $v = array(); while ($v = mysql_fetch_array($validstocks)) { $qty = $v['sh_qty']; $creditamnt = $v['sh_nowprice'] * $qty; $newprice = $v['sh_nowprice']; $q_ry = array(); $q_ry = "UPDATE `members` SET `wallet` = `wallet` + '" . mysql_real_escape_string($creditamnt) . "' WHERE `playerid` = '" . mysql_real_escape_string($v['sh_playerid']) . "'"; mysql_query($q_ry); $message = "Someone bought " . $qty . " of your stocks for \$" . number_format($creditamnt) . "!"; in_event($v['sh_playerid'], $message); $q_ry = array(); $q_ry = "UPDATE `stock_holdings` SET `sh_playerid` = '1', `sh_payed` = '" . mysql_real_escape_string($newprice) . "', `sh_time` = '" . time() . "', `sh_sale` = '1', `sh_saletime` = '" . time() . "' WHERE `sh_id` = '" . mysql_real_escape_string($v['sh_id']) . "'"; mysql_query($q_ry) or die(mysql_error()); } $yearago = (time() - 32140800); $sixmonths = $yearago / 2; $threemonths = $sixmonths / 2; $onemonth = $sixmonths / 6; $twoweeks = $onemonth / 2; $q_ry = array(); $q_ry = "DELETE FROM `member_mail` WHERE `mm_time` <= '" . mysql_real_escape_string($onemonth) . "'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "DELETE FROM `member_events` WHERE `e_time` <= '" . mysql_real_escape_string($onemonth) . "'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "DELETE FROM `attack_logs` WHERE `time` <= '" . mysql_real_escape_string($onemonth) . "'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "DELETE FROM `faction_events` WHERE `fe_time` <= '" . mysql_real_escape_string($onemonth) . "'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "DELETE FROM `profile_comments` WHERE `pc_time` <= '" . mysql_real_escape_string($twoweeks) . "'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "DELETE FROM `profile_replies` WHERE `pr_time` <= '" . mysql_real_escape_string($twoweeks) . "'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "DELETE FROM `stock_history` WHERE `h_time` <= '" . mysql_real_escape_string($sixmonths) . "'"; mysql_query($q_ry) or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
~Rob0t Posted August 28, 2015 Share Posted August 28, 2015 Are you sure it's timing out (ie: reaching 30seconds execution) or that there is a MySQL error and die is causing the script to stop execution? My question: What debugging have you done? Quote Link to comment Share on other sites More sharing options...
IllegalPigeon Posted August 28, 2015 Share Posted August 28, 2015 Can't really help unless you try to debug it a bit and give us the errors. Also, why are you quoting numbers in your queries? Number != string. I won't comment on the plethora of issues within that file, just the number thing...as it's sticking out. Quote Link to comment Share on other sites More sharing options...
Coly010 Posted August 28, 2015 Share Posted August 28, 2015 Can't really help unless you try to debug it a bit and give us the errors. Also, why are you quoting numbers in your queries? Number != string. I won't comment on the plethora of issues within that file, just the number thing...as it's sticking out. back-ticks ? ;) Quote Link to comment Share on other sites More sharing options...
IllegalPigeon Posted August 28, 2015 Share Posted August 28, 2015 back-ticks ? ;) I feel like I've adequately expressed my feelings towards this forum and it's use of back-ticks. If I have to discuss it again, I'll cry. Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted August 28, 2015 Author Share Posted August 28, 2015 Are you sure it's timing out (ie: reaching 30seconds execution) or that there is a MySQL error and die is causing the script to stop execution? My question: What debugging have you done? Yes it is timing out, then my site goes to a 500 error for around 15 minutes, I contacted my service provider, because this problem has only started to occur over the last four or so days. At first I didn't pay much attention to it at all, untill I noticed that my age (days I've been playing) is going up by two. No there's no duplicate query. - - - Updated - - - back-ticks ? ;) Why would that cause it to time out and update twice? Quote Link to comment Share on other sites More sharing options...
jcvenom Posted August 28, 2015 Share Posted August 28, 2015 Yes it is timing out, then my site goes to a 500 error for around 15 minutes, I contacted my service provider, because this problem has only started to occur over the last four or so days. At first I didn't pay much attention to it at all, untill I noticed that my age (days I've been playing) is going up by two. No there's no duplicate query. - - - Updated - - - Why would that cause it to time out and update twice? Check your error logs in the cron directory for any issue's regarding that file and also check your hosting email for cron run logs Quote Link to comment Share on other sites More sharing options...
Coly010 Posted August 28, 2015 Share Posted August 28, 2015 Why would that cause it to time out and update twice? it doesn't. Inside joke, just ignore. 1 Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted August 28, 2015 Share Posted August 28, 2015 if your getting a 505 error is that not due to your code using to much resources and host shutting it down as some shared hosting does it Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted August 28, 2015 Author Share Posted August 28, 2015 (edited) if your getting a 505 error is that not due to your code using to much resources and host shutting it down as some shared hosting does it I'm using a vps, and it's just a 500 error. I will turn error reporting on and manually run it Edited August 28, 2015 by -BRAIDZ- Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted August 29, 2015 Author Share Posted August 29, 2015 I have removed most of the "mysql_real_escape_string()" and all of the back-ticks, theres some of the mysql_real_escape_string() that I don't want to touch... Is this correct? <?php $dbhost = "localhost"; $dbuser = "blah"; $dbpass = "nottellingyou"; $dbbase = "mygameduh"; $cron_are_so_cool = "trick_is_da_bomb"; $db = "mysql_tut"; $con = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbbase); if ($_GET['code_to_run'] < 0) { die("<center><font color=red>Fatal error!</font> <blink>IP logged as {$_SERVER['REMOTE_ADDR']}</blink></center>"); } else { /*----------------------------------Start cron minutes--------------------------*/ mysql_query("UPDATE members SET my_mailban = my_mailban - 1 WHERE my_mailban >= 1 ") or die(mysql_error()); mysql_query("UPDATE members SET my_forumban = my_forumban - 1 WHERE my_forumban >= 1 ") or die(mysql_error()); mysql_query("UPDATE none_agressive SET na_days = na_days - 1 WHERE na_days >= 1 ") or die(mysql_error()); mysql_query("DELETE FROM none_agressive WHERE na_days <= 0") or die(mysql_error()); mysql_query("UPDATE city_shop_dogs SET csd_daysold = csd_daysold + 1") or die(mysql_error()); mysql_query("UPDATE members_dogs SET md_daysold = md_daysold + 1") or die(mysql_error()); $newones = rand(1, 15); $morf = array( 1 => 'male', 2 => 'female' ); for ($i = 1; $i <= $newones; $i++) { $q_ry = array(); $q_ry = "INSERT INTO city_shop_dogs VALUES('NULL', '" . rand(1, 8) . "', '" . $morf[rand(1, 2)] . "', 0)"; mysql_query($q_ry) or die(mysql_error()); } $withjob = array(); $wj = array(); $q_ry = array(); $q_ry = "SELECT me.my_job,me.my_job_rank,me.playerid, sjr.*,m.my_level FROM members_extra me INNER JOIN system_job_ranks AS sjr ON me.my_job_rank = sjr.r_ID INNER JOIN members AS m ON me.playerid = m.playerid WHERE me.my_job > 0"; $withjob = array(); $withjob = mysql_query($q_ry) or die(mysql_error()); $wj = array(); while ($wj = mysql_fetch_array($withjob)) { $q_ry = array(); $q_ry = "UPDATE memberstats SET my_labor = my_labor + '" . mysql_real_escape_string($wj['r_MANUALGAIN']) . "', my_intelligence = my_intelligence + '" . mysql_real_escape_string($wj['r_INTELGAIN']) . "', my_endurance = my_endurance + '" . mysql_real_escape_string($wj['r_ENDURGAIN']) . "' WHERE playerid = '" . mysql_real_escape_string($wj['playerid']) . "'"; mysql_query($q_ry) or die(mysql_error()); $job = array( 1 => 'armypoints', 2 => 'grocpoints', 3 => 'casipoints', 4 => 'medipoints', 5 => 'educpoints', 6 => 'lawpoints' ); $wj['r_POINTS'] *= $wj['my_level']; $q_ry = array(); $q_ry = "UPDATE members_extra SET " . $job[$wj['my_job']] . " = " . $job[$wj['my_job']] . " + '" . mysql_real_escape_string($wj['r_POINTS']) . "' WHERE playerid = '" . mysql_real_escape_string($wj['playerid']) . "'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "UPDATE members SET wallet = wallet + '" . mysql_real_escape_string($wj['r_WAGES']) . "' WHERE playerid = '" . mysql_real_escape_string($wj['playerid']) . "'"; mysql_query($q_ry) or die(mysql_error()); } function remove_staff($id) { $q_ry = array(); $q_ry = "SELECT p_maids,p_butler,p_guard,p_doctor,p_pilot FROM members_properties WHERE p_id = $id "; $uptime = array(); $uptime = mysql_query($q_ry); $ut = array(); $ut = mysql_fetch_array($uptime); $happloss = 0; if ($ut['p_maids'] != 0) { $q_ry = array(); $q_ry = "SELECT ps_name FROM property_staff WHERE ps_id = '" . mysql_real_escape_string($ut['p_maids']) . "'"; $wichmaids = array(); $wichmaids = mysql_query($q_ry); $wms = mysql_fetch_array($wichmaids); $wms = array(); if ($wms['ps_name'] == '5x Maid Service') { $happloss += 100; } if ($wms['ps_name'] == '3x Maid Service') { $happloss += 85; } if ($wms['ps_name'] == '2x Maid Service') { $happloss += 75; } if ($wms['ps_name'] == 'Maid Service') { $happloss += 50; } } if ($ut['p_butler'] != 0) { $q_ry = array(); $q_ry = "SELECT ps_name FROM property_staff WHERE ps_id = '" . mysql_real_escape_string($ut['p_butler']) . "'"; $wichbutlers = array(); $wichbutlers = mysql_query($q_ry); $wmb = mysql_fetch_array($wichbutlers); $wmb = array(); if ($wmb['ps_name'] == '3x Butler Service') { $happloss += 125; } if ($wmb['ps_name'] == '2x Butler Service') { $happloss += 100; } if ($wmb['ps_name'] == 'Butler Service') { $happloss += 75; } } if ($ut['p_guard'] != 0) { $q_ry = array(); $q_ry = "SELECT ps_name FROM property_staff WHERE ps_id='" . mysql_real_escape_string($ut['p_guard']) . "'"; $wichguards = array(); $wichguards = mysql_query($q_ry); $wmg = mysql_fetch_array($wichguards); $wmg = array(); if ($wmg['ps_name'] == '10x Guard Service') { $happloss += 500; } if ($wmg['ps_name'] == '5x Guard Service') { $happloss += 300; } if ($wmg['ps_name'] == '3x Guard Service') { $happloss += 200; } if ($wmg['ps_name'] == '2x Guard Service') { $happloss += 150; } if ($wmg['ps_name'] == 'Guard Service') { $happloss += 100; } } if ($ut['p_doctor'] != 0) { $happloss += 25; } if ($ut['p_pilot'] != 0) { $happloss += 50; } $q_ry = array(); $q_ry = "UPDATE members_properties SET p_happy = p_happy - $happloss ', p_maids = 0, p_butler = 0, p_guard = 0, p_doctor = 0, p_pilot = 0, p_priceofstaff = 0, p_daysofstaff = 0 WHERE p_id = $id "; mysql_query($q_ry); $q_ry = array(); $q_ry = "UPDATE members SET my_maxhappy = my_maxhappy - $happloss ' WHERE my_property = $id "; mysql_query($q_ry); } function in_event($player, $text) { $player = abs(intval($player)); $text = stripslashes($text); mysql_query("INSERT INTO member_events VALUES('NULL', $player , $text , unix_timestamp(), 0)") or die(mysql_error()); mysql_query("UPDATE city_statistic SET cs_value = cs_value + 1 WHERE cs_id = 1") or die(mysql_error()); } function stock_credit($id, $credit) { $q_ry = array(); $q_ry = "UPDATE stock_market SET s_profit = s_profit + $credit , s_losses = s_losses - $credit WHERE s_id = $id "; mysql_query($q_ry); $q_ry = array(); $q_ry = "UPDATE stock_market SET s_profit = 0 WHERE s_profit <= 0"; mysql_query($q_ry); $q_ry = array(); $q_ry = "UPDATE stock_market SET s_losses = 0 WHERE s_losses <= 0"; mysql_query($q_ry); } mysql_query("UPDATE members_properties SET p_ltime = p_ltime - 1 WHERE p_leasedto > 0"); mysql_query("UPDATE members_properties SET p_daysofstaff = p_daysofstaff + 1 WHERE p_priceofstaff > 0"); //Check for expired rentings $q_ry = array(); $q_ry = "SELECT * FROM members_properties mp LEFT JOIN properties h ON mp.p_property = h.house_id WHERE mp.p_leasedto != 0 AND mp.p_ltime = 0"; $uptime = array(); $uptime = mysql_query($q_ry); while ($ut = mysql_fetch_array($uptime)) { $message1 = "The rent period for your " . htmlentities($ut['house_name']) . " has now finished, The " . htmlentities($ut['house_name']) . " has been returned to you."; $q_ry = array(); $q_ry = "INSERT INTO member_events VALUES ('NULL', '" . mysql_real_escape_string($ut['p_playerid']) . "', $message1 , unix_timestamp(), 0)"; mysql_query($q_ry); $message2 = "The rent period for the " . htmlentities($ut['house_name']) . " has now finished, The " . htmlentities($ut['house_name']) . " has been returned to its owner."; $q_ry = array(); $q_ry = "INSERT INTO member_events VALUES ('NULL', '" . mysql_real_escape_string($ut['p_leasedto']) . "', $message2 , unix_timestamp(), 0)"; mysql_query($q_ry); $q_ry = array(); $q_ry = "SELECT playerid FROM members WHERE my_property = '" . mysql_real_escape_string($ut['p_id']) . "'"; $mys = array(); $mys = mysql_query($q_ry); if (mysql_num_rows($mys)) { $my = array(); while ($my = mysql_fetch_array($mys)) { $q_ry = array(); $q_ry = "SELECT p_id FROM members_properties WHERE p_playerid = '" . mysql_real_escape_string($my['playerid']) . "' AND p_property = 1"; $myshack = array(); $myshack = mysql_query($q_ry); $msh = array(); $msh = mysql_fetch_array($myshack); $q_ry = array(); $q_ry = "UPDATE members SET my_property = '" . mysql_real_escape_string($msh['p_id']) . "', my_happy = '100', my_maxhappy = '100' WHERE playerid = '" . mysql_real_escape_string($my['playerid']) . "'"; mysql_query($q_ry); } } remove_staff($ut['p_id']); $q_ry = array(); $q_ry = "UPDATE members_properties SET p_leasedto = 0, p_ltime = 0 WHERE p_id = '" . mysql_real_escape_string($ut['p_id']) . "'"; mysql_query($q_ry); } //Check for expired rentings //Charge daily upkeep $q_ry = array(); $q_ry = "SELECT * FROM members_properties mp LEFT JOIN properties h ON mp.p_property = h.house_id WHERE mp.p_property != 1"; $upprops = array(); $upprops = mysql_query($q_ry); $up = array(); while ($up = mysql_fetch_array($upprops)) { $total = ($up['p_priceofstaff'] + $up['house_tax']); if ($up['p_leasedto'] != 0) { //Check money of tenant $q_ry = array(); $q_ry = "SELECT playerid FROM members WHERE playerid = '" . mysql_real_escape_string($up['p_leasedto']) . "' AND wallet <= '- $total "; $myc = array(); $myc = mysql_query($q_ry); if ($up['p_priceofstaff']) { stock_credit(5, 1); if (mysql_num_rows($myc)) { remove_staff($up['p_id']); $message3 = "You did not have enough to pay your staff for today, They have packed up and left!"; in_event($up['p_leasedto'], $message3); } } $q_ry = array(); $q_ry = "UPDATE members SET wallet = wallet - $total WHERE playerid = '" . mysql_real_escape_string($up['p_leasedto']) . "'"; } else { //Check money of member $q_ry = array(); $q_ry = "SELECT wallet FROM members WHERE playerid = '" . mysql_real_escape_string($up['p_playerid']) . "' AND wallet <= '- $total "; $myc = array(); $myc = mysql_query($q_ry); if ($up['p_priceofstaff']) { stock_credit(5, 1); if (mysql_num_rows($myc)) { remove_staff($up['p_id']); $message3 = "You did not have enough to pay your staff for today, They have packed up and left!"; in_event($up['p_playerid'], $message3); } } $q_ry = array(); $q_ry = "UPDATE members SET wallet = wallet - $total WHERE playerid = '" . mysql_real_escape_string($up['p_playerid']) . "'"; } mysql_query($q_ry); } //Charge daily upkeep /*-----------------------------------End cron minutes---------------------------*/ function award_check($user, $number, $award) { $q_ry = array(); $q_ry = "SELECT ma_id,ma_tier FROM members_awards WHERE ma_playerid = $user AND ma_award = $award "; $got_award = array(); $got_award = mysql_query($q_ry) or die(mysql_error()); if (mysql_num_rows($got_award)) { $ga = array(); $ga = mysql_fetch_array($got_award); if ($ga['ma_tier'] >= $number) { //Got it } else { $q_ry = array(); $q_ry = "UPDATE members_awards SET ma_tier = $number , ma_viewed = 0, ma_time = unix_timestamp() WHERE ma_id = '" . mysql_real_escape_string($ga['ma_id']) . "'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "UPDATE members SET my_merits = my_merits + 1 WHERE playerid = $user "; mysql_query($q_ry) or die(mysql_error()); } } else { $q_ry = array(); $q_ry = "INSERT INTO members_awards VALUES ('NULL', $award , $number ', $user , 0, unix_timestamp())"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "UPDATE members SET my_merits = my_merits + 1 WHERE playerid = $user "; mysql_query($q_ry) or die(mysql_error()); } } $q_ry = array(); $q_ry = "SELECT * FROM award_checks ac LEFT JOIN awards a ON ac.ac_award_id = a.a_id"; $award_checks = array(); $award_checks = mysql_query($q_ry) or die(mysql_error()); while ($aw = mysql_fetch_array($award_checks)) { $q_ry = array(); $q_ry = "SELECT " . $aw['ac_identify'] . "," . $aw['ac_what'] . " FROM " . $aw['ac_table'] . " WHERE " . $aw['ac_what'] . " >= '" . $aw['ac_amount'] . "'"; $thisaward = array(); $thisaward = mysql_query($q_ry) or die(mysql_error()); if (mysql_num_rows($thisaward)) { while ($ta = mysql_fetch_array($thisaward)) { award_check($ta[$aw['ac_identify']], $aw['ac_number'], $aw['ac_award_id']); } } } mysql_query("UPDATE members SET my_dondays = my_dondays - 1 WHERE my_dondays > 0"); mysql_query("UPDATE members SET my_maxenergy = '100' WHERE my_dondays <= 0"); mysql_query("UPDATE members SET my_partner_days = my_partner_days + 1 WHERE my_partner > 0"); mysql_query("UPDATE members SET brew = 0"); mysql_query("UPDATE members_extra SET my_daysold = my_daysold + 1"); mysql_query("UPDATE members_extra SET my_ctokens = my_ctokens_daily,my_cstreak = 0"); mysql_query("UPDATE members_extra SET energy_refill = 0"); $q_ry = array(); $q_ry = "SELECT playerid FROM members WHERE my_faction > 0"; $facdays = array(); $facdays = mysql_query($q_ry) or die(mysql_error()); $fd = array(); $q_ry = array(); while ($fd = mysql_fetch_array($facdays)) { $q_ry = "UPDATE members_extra SET my_faction_days = my_faction_days + 1 WHERE playerid = '" . mysql_real_escape_string($fd['playerid']) . "'"; mysql_query($q_ry) or die(mysql_error()); } $q_ry = array(); $q_ry = "DELETE FROM votes_count WHERE vc_site = 'apex' || vc_site = 'ultra'"; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "SELECT * FROM stock_holdings WHERE sh_saletime > 0 AND (sh_saletime+1036800) <= '" . (time()) . "' AND sh_playerid != '3'"; $validstocks = array(); $validstocks = mysql_query($q_ry) or die(mysql_error()); $v = array(); while ($v = mysql_fetch_array($validstocks)) { $qty = $v['sh_qty']; $creditamnt = $v['sh_nowprice'] * $qty; $newprice = $v['sh_nowprice']; $q_ry = array(); $q_ry = "UPDATE members SET wallet = wallet + $creditamnt ' WHERE playerid = '" . mysql_real_escape_string($v['sh_playerid']) . "'"; mysql_query($q_ry); $message = "Someone bought " . $qty . " of your stocks for \$" . number_format($creditamnt) . "!"; in_event($v['sh_playerid'], $message); $q_ry = array(); $q_ry = "UPDATE stock_holdings SET sh_playerid = 1, sh_payed = '" . mysql_real_escape_string($newprice) . "', sh_time = '" . time() . "', sh_sale = 1, sh_saletime = '" . time() . "' WHERE sh_id = '" . mysql_real_escape_string($v['sh_id']) . "'"; mysql_query($q_ry) or die(mysql_error()); } $yearago = (time() - 32140800); $sixmonths = $yearago / 2; $threemonths = $sixmonths / 2; $onemonth = $sixmonths / 6; $twoweeks = $onemonth / 2; $q_ry = array(); $q_ry = "DELETE FROM member_mail WHERE mm_time <= $onemonth "; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "DELETE FROM member_events WHERE e_time <= $onemonth "; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "DELETE FROM attack_logs WHERE time <= $onemonth "; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "DELETE FROM faction_events WHERE fe_time <= $onemonth "; mysql_query($q_ry) or die(mysql_error()); $q_ry = array(); $q_ry = "DELETE FROM stock_history WHERE h_time <= $sixmonths "; mysql_query($q_ry) or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted August 29, 2015 Author Share Posted August 29, 2015 This is the only error I am getting when I manually run the cron You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= + '200' WHERE playerid = '5'' at line 2 Quote Link to comment Share on other sites More sharing options...
Coly010 Posted August 29, 2015 Share Posted August 29, 2015 From looking through your file I have a feeling it may be to do with you $withjob query thing. Your file is a mess, that's as well as I can explain what line it is whilst on my phone. I can't copy and paste it. Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted August 29, 2015 Author Share Posted August 29, 2015 From looking through your file I have a feeling it may be to do with you $withjob query thing. Your file is a mess, that's as well as I can explain what line it is whilst on my phone. I can't copy and paste it. This bit here? FROM members_extra me INNER JOIN system_job_ranks AS sjr ON me.my_job_rank = sjr.r_ID INNER JOIN members AS m ON me.playerid = m.playerid WHERE me.my_job > 0"; I think I see the problem? me.playerid = m.playerid Should be: me.playerid = $me.playerid I will change this and see what happens and see if I get anymore errors and will post them here :) Quote Link to comment Share on other sites More sharing options...
jcvenom Posted August 29, 2015 Share Posted August 29, 2015 This bit here? FROM members_extra me INNER JOIN system_job_ranks AS sjr ON me.my_job_rank = sjr.r_ID INNER JOIN members AS m ON me.playerid = m.playerid WHERE me.my_job > 0"; I think I see the problem? me.playerid = m.playerid Should be: me.playerid = $me.playerid I will change this and see what happens and see if I get anymore errors and will post them here :) That's not the issue me.playerid = m.playerid its meant to be like that, the m. part of the code is the members table of your query Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted August 29, 2015 Author Share Posted August 29, 2015 That's not the issue me.playerid = m.playerid its meant to be like that, the m. part of the code is the members table of your query Okay, why does the others have the me bit? Quote Link to comment Share on other sites More sharing options...
spikereloaded Posted August 29, 2015 Share Posted August 29, 2015 (edited) me.playerid - m.playerid is telling the query to compare the playerid from the members_extra (me.playerid) table to the playerid from the members(m.playerid) table. wherever there is a me. or a m. you are pulling the value from the members_extra table (me.) or the members table (m.) so in the inner join, you're joining the two table where the playerid's are the same. Edited August 29, 2015 by spikereloaded Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted August 29, 2015 Author Share Posted August 29, 2015 me.playerid - m.playerid is telling the query to compare the playerid from the members_extra (me.playerid) table to the playerid from the members(m.playerid) table. wherever there is a me. or a m. you are pulling the value from the members_extra table (me.) or the members table (m.) so in the inner join, you're joining the two table where the playerid's are the same. Thanks, I now understand :) Hopefully I can work this out :) Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted August 29, 2015 Share Posted August 29, 2015 I'm using a vps, and it's just a 500 error. I will turn error reporting on and manually run it Ah ok but are you using up your vps resources ? checks the backend if you have whm access or whatever Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted August 29, 2015 Author Share Posted August 29, 2015 Ah ok but are you using up your vps resources ? checks the backend if you have whm access or whatever I'm using SSH Crontab.. My company cron was updating twice, so I removed it from the cron tab, and it updated once, so I think I might remove the daily cron and see if that's the problem, it is probably updating from two separate locations.. So from the updated cron I have posted where I've removed the mysql_real_escape_string from most of the queries, do I have to remove anymore? Because the ones left I don't want to touch. Unless someone could explain to me what to do? Thank you Quote Link to comment Share on other sites More sharing options...
IllegalPigeon Posted August 29, 2015 Share Posted August 29, 2015 I'm using SSH Crontab.. My company cron was updating twice, so I removed it from the cron tab, and it updated once, so I think I might remove the daily cron and see if that's the problem, it is probably updating from two separate locations.. So from the updated cron I have posted where I've removed the mysql_real_escape_string from most of the queries, do I have to remove anymore? Because the ones left I don't want to touch. Unless someone could explain to me what to do? Thank you You're using mysql_real_escape_string() to escape numbers. That's not what it's meant to be used for. The hint is in the name...string. You're also still quoting numbers. If you were running out of resources, then, that's not helping. It forces MySQL to typecast/conversion, which, on a script that's already haemorrhaging resources is not helping. That's not why your script isn't running, though. It's down to whatever query you have that is throwing an error. We'd need to see that query. Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted August 29, 2015 Author Share Posted August 29, 2015 You're using mysql_real_escape_string() to escape numbers. That's not what it's meant to be used for. The hint is in the name...string. You're also still quoting numbers. If you were running out of resources, then, that's not helping. It forces MySQL to typecast/conversion, which, on a script that's already haemorrhaging resources is not helping. That's not why your script isn't running, though. It's down to whatever query you have that is throwing an error. We'd need to see that query. Okay, so I have removed most of the mysql_real_escape_string's but these ones here, I didn't want to touch them and screw the whole thing up, what do I do with these ones? And the name string? mysql_real_escape_string($ut['p_leasedto']) Quote Link to comment Share on other sites More sharing options...
IllegalPigeon Posted August 29, 2015 Share Posted August 29, 2015 Okay, so I have removed most of the mysql_real_escape_string's but these ones here, I didn't want to touch them and screw the whole thing up, what do I do with these ones? And the name string? mysql_real_escape_string($ut['p_leasedto']) What I'm saying is that you're using mysql_real_escapestring() on numbers. Notice the "STRING" at the end of that function name. A number is NOT a string. Example: WHERE playerid = '" . mysql_real_escape_string($wj['playerid']) . "'"; , that looks like a number to me, you're using MRES() on it AND quoting it. It's a number. But, I don't know your system, you could be referencing a players name in the "playerid" field. I just don't know...I didn't make it. WHERE playerid = " . $wj['playerid']; Would be a better usage. Or, if you're unsure what the contents of $wj['playerid'] is going to be and you want to force it, then you'd use: WHERE playerid = " . intval($wj['playerid']); But, in reality, you should even be using the MySQL extension. Quote Link to comment Share on other sites More sharing options...
spikereloaded Posted August 29, 2015 Share Posted August 29, 2015 what query is your error actually relating to? is it anything to do with this? $q_ry = "UPDATE members_extra SET " . $job[$wj['my_job']] . " = " . $job[$wj['my_job']] . " + '" . mysql_real_escape_string($wj['r_POINTS']) . "' WHERE playerid = '" . mysql_real_escape_string($wj['playerid']) . "'"; Also i'd look into using prepred statements and get rid of MRES() all together. Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted August 30, 2015 Author Share Posted August 30, 2015 what query is your error actually relating to? is it anything to do with this? $q_ry = "UPDATE members_extra SET " . $job[$wj['my_job']] . " = " . $job[$wj['my_job']] . " + '" . mysql_real_escape_string($wj['r_POINTS']) . "' WHERE playerid = '" . mysql_real_escape_string($wj['playerid']) . "'"; Also i'd look into using prepred statements and get rid of MRES() all together. I'm not sure, it's saying about line two, but line two is the the host.. And that's correct. All it doing is running twice, but there is nothing about it running twice in the logs, so it's either a problem with the code itself, or its updating from two separate locations? Not sure how though, seems that was the problem with one of my other daily crons. And I'll look into it thanks 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.