Jump to content

A unusual error


NArc0t1c

Recommended Posts

Hello.

 

I have a problem with a script I am trying to make.

I know it's correct, but it giving me an Unsupported operand types error.

 

What causes this?

It's an if statement, with a calculation; surely it cannot be that!

 

Here is a part of the script:

<?php

  $time = time(); // Generate time.
  $cron_minute_run = 60; // Seconds in a minute.
  $last_minute_run = file("crons/cron_minute.txt"); // Get previous time.

  if ($time - $last_minute_run >= $cron_minute_run) {
      $start_min_timer = microtime(); // Start timer.
      if ($time - $last_minute_run / 60 > 1) { 
          $minute_run_no = $time - $last_minute_run / 60; // Calculate how many times to run.
      } else {
          $minute_run_no = 1; // Only run once.
      }

      for ($i = 0; $i < $minute_run_no; $i++) { // Run x times.
          $do = mysql_query("UPDATE table SET col_2=col_2-1 WERE other > 0", $c);
          $do = mysql_query("UPDATE table SET col=col-1 WHERE other > 0", $c);
          if (empty($do)) {
              mail("[email protected]", "Minute Cron not run.", "The minute cron could not run because of a mysql error.", "From: [email protected]"); // Send mail stating there is an error.
          } else {
              $open = fopen("crons/cron_minute.txt", "w"); //Write time to file for next use.
              fputs($open, time());
              fclose($open);
              $end_min_timer = microtime(); // End timer.
              $total_min_timer = $start_min_timer - $end_min_timer; // Calculate timer.
              mail("[email protected]", "Minute Cron was run.", "The minute cron was run succesfully.\r\n" . "Time: $time\r\n" . "Time Took: $start_min_timer - $end_min_timer\r\n" . "Total: $total_min_timer.", "From: [email protected]"); // Send a mail for statistics.
          }
      }
  }
exit; //No need to continue.

?>

 

Thanks..

 

Link to comment
https://forums.phpfreaks.com/topic/63011-a-unusual-error/
Share on other sites

As you don't report which line of code this is on I can only guess its in the math doen inside the if statements...

 

try this...

 

<?php

 $time = time(); // Generate time.
 $cron_minute_run = 60; // Seconds in a minute.
 $last_minute_run = file("crons/cron_minute.txt"); // Get previous time.

 if (($time - $last_minute_run) >= $cron_minute_run) {
     $start_min_timer = microtime(); // Start timer.
     if ((($time - $last_minute_run) / 60) > 1) { 
         $minute_run_no = ($time - $last_minute_run) / 60; // Calculate how many times to run.
     } else {
         $minute_run_no = 1; // Only run once.
     }

     for ($i = 0; $i < $minute_run_no; $i++) { // Run x times.
         $do = mysql_query("UPDATE table SET col=col-1, col_2=col_2-1 WERE other > 0", $c);
         if (!empty(mysql_error())) {
             mail("[email protected]", "Minute Cron not run.", "The minute cron could not run because of a mysql error.", "From: [email protected]"); // Send mail stating there is an error.
         } else {
             $open = fopen("crons/cron_minute.txt", "w"); //Write time to file for next use.
             fputs($open, time());
             fclose($open);
             $end_min_timer = microtime(); // End timer.
             $total_min_timer = $start_min_timer - $end_min_timer; // Calculate timer.
             mail("[email protected]", "Minute Cron was run.", "The minute cron was run succesfully.\r\n" . "Time: $time\r\n" . "Time Took: $start_min_timer - $end_min_timer\r\n" . "Total: $total_min_timer.", "From: [email protected]"); // Send a mail for statistics.
         }
     }
 }
exit; //No need to continue.

?>

 

changed you query string as well so you only run one query...

 

You MUST take note of the precedence of operators when you use them in conjunction with one another!!!!!!!!!!

 

x - y / z  would be x subtract y divided by z that measn y would be divided by z first and then subtracted from x - great if that is what you want - if you wanted the result of x - y divided by z then

 

(x-y)/z is the correct structure...

Link to comment
https://forums.phpfreaks.com/topic/63011-a-unusual-error/#findComment-313790
Share on other sites

Error on line 14:

The if statement.

Original error:

Fatal error: Unsupported operand types in /hsphere/local/home/user/parth/script.php on line 13

 

 

ToonMariner, the queries were just examples, there are about 30 queries and some file I\O.

I have tried it that way, in brackets, still doesn't work.

Thanks though.

 

Link to comment
https://forums.phpfreaks.com/topic/63011-a-unusual-error/#findComment-313797
Share on other sites

I'm not looking for an argument.

 

The full script is:

<?php

  $time = time();
  $cron_minute_run = 60;
  $cron_fminute_run = 60 * 5;
  $cron_hour_run = 60 * 60;
  $cron_day_run = 60 * 60 * 24;
  
  $last_minute_run = file("crons/cron_minute.txt");
  $last_fminute_run = file("crons/cron_fiveminute.txt");
  $last_hour_run = file("crons/cron_hour.txt");
  $last_day_run = file("crons/cron_day.txt");
  if ($time - $last_minute_run >= $cron_minute) {
      $start_min_timer = microtime();
      if (($time - $last_minute_run) / 60 > 1) {
          $minute_run_no = $time - $last_minute_run / 60;
      } else {
          $minute_run_no = 1;
      }
      for ($i = 0; $i < $minute_run_no; $i++) {
          $do = mysql_query("UPDATE users SET hospital=hospital-1 WERE hospital > 0", $c);
          $do = mysql_query("UPDATE users SET jail=jail-1 WHERE jail > 0", $c);
          
          mysql_query("UPDATE `auctions` SET time=`time`-1");
          $qqq = mysql_query("SELECT * FROM `auctions` WHERE time=0", $c);
          while ($win = mysql_fetch_array($qqq)) {
              $time = $win['time'];
              $item = $win['itemname'];
              $winner = $win['bidder'];
              $owner = $win['owner'];
              
              $iname = mysql_query("SELECT `itmname` FROM `items` WHERE itmid={$item}");
              if ($win['bids'] > 0) {
                  mysql_query("insert into `inventory` VALUES('',$item,$winner,1)", $c) or die(mysql_error());
                  event_add($winner, "You won the auction of the {$iname} for \${$win['current']}", $c);
                  event_add($owner, "Your {$iname} sold succesfully on the auction market with {$win['bids']} bids. You have been paid \${$win['current']}", $c);
                  mysql_query("update users set money=money+{$win['current']},auctionquota=auctionquota-1 where userid=$owner", $c);
              }
              if ($win['bids'] == 0) {
                  event_add($win['owner'], "Your auction has ended with no bidders. Your {$iname} has been returned to your inventory.", $c);
                  
                  $winner = $win['owner'];
                  
                  mysql_query("insert into `inventory` VALUES('',$item,$winner,1)", $c) or die(mysql_error());
              }
          }
          mysql_query("delete from `auctions` where time=0", $c);
          
          
          
          if (empty($do)) {
              mail("[email protected]", "Minute Cron not run.", "The minute cron could not run because of a mysql error.", "From: [email protected]");
          } else {
              $open = fopen("crons/cron_minute.txt", "w");
              fputs($open, time());
              fclose($open);
              $end_min_timer = microtime();
              $total_min_timer = $start_min_timer - $end_min_timer;
              mail("[email protected]", "Minute Cron was run.", "The minute cron was run succesfully.\r\n" . "Time: $time\r\n" . "Time Took: $start_min_timer - $end_min_timer\r\n" . "Total: $total_min_timer.", "From: [email protected]");
          }
      }
  }
  
  if ($time - $last_fminute_run >= $cron_fminute_run) {
      $start_fmin_timer = microtime();
      if ($time - $last_fminute_run / 60 > 1) {
          $fminute_run_no = $time - $last_fminute_run / 60;
      } else {
          $fminute_run_no = 1;
      }
      for ($i = 0; $i < $fminute_run_no; $i++) {
          $q1 = mysql_query("SELECT COUNT(*) as users FROM users", $c);
          $r = mysql_fetch_array($q1);
          $rows = $r['users'];
          $i = 1;
          $next = $rows;
          $query = "UPDATE users SET brave=brave+((maxbrave/10)+0.5) WHERE brave<maxbrave ";
          $query2 = "UPDATE users SET brave=maxbrave WHERE brave>maxbrave";
          $query3 = "UPDATE users SET hp=hp+(maxhp/3) WHERE hp<maxhp";
          $query4 = "UPDATE users SET hp=maxhp WHERE hp>maxhp";
         $do =  mysql_query($query, $c) or die("\nError Executing Query 1 for updating users $i to $next\n$query\n" . mysql_error() . "\nError Code:" . mysql_errno());
          mysql_query($query2, $c) or die("\nError Executing Query 2 for updating users $i to $next\n$query2\n" . mysql_error() . "\nError Code:" . mysql_errno());
          mysql_query($query3, $c) or die("\nError Executing Query 3 for updating users $i to $next\n$query3\n" . mysql_error() . "\nError Code:" . mysql_errno());
          mysql_query($query4, $c) or die("\nError Executing Query 4 for updating users $i to $next\n$query4\n" . mysql_error() . "\nError Code:" . mysql_errno());
          
          $q1 = mysql_query("SELECT COUNT(*) as users FROM users", $c);
          $r = mysql_fetch_array($q1);
          $rows = $r['users'];
          $i = 1;
          $next = $rows;
          $query = "UPDATE users SET energy=energy+(maxenergy/(12.5)) WHERE energy<maxenergy AND donatordays=0";
          $query5 = "UPDATE users SET energy=energy+(maxenergy/(6)) WHERE energy<maxenergy AND donatordays>0";
          $query2 = "UPDATE users SET energy=maxenergy WHERE energy>maxenergy";
          $query3 = "UPDATE users SET will=will+10 WHERE will<maxwill";
          $query4 = "UPDATE users SET will=maxwill WHERE will>maxwill";
          mysql_query($query, $c) or die("\nError Executing Query 1 for updating users $i to $next\n$query\n" . mysql_error() . "\nError Code:" . mysql_errno());
          mysql_query($query5, $c) or die("\nError Executing Query 5 for updating users $i to $next\n$query5\n" . mysql_error() . "\nError Code:" . mysql_errno());
          mysql_query($query2, $c) or die("\nError Executing Query 2 for updating users $i to $next\n$query2\n" . mysql_error() . "\nError Code:" . mysql_errno());
          mysql_query($query3, $c) or die("\nError Executing Query 3 for updating users $i to $next\n$query3\n" . mysql_error() . "\nError Code:" . mysql_errno());
          mysql_query($query4, $c) or die("\nError Executing Query 4 for updating users $i to $next\n$query4\n" . mysql_error() . "\nError Code:" . mysql_errno());
          
          if (empty($do)) {
              mail("[email protected]", "Five Minute Cron not run.", "The five minute cron could not run because of a mysql error.", "From: [email protected]");
          } else {
              $open = fopen("crons/cron_fiveminute.txt", "w");
              fputs($open, time());
              fclose($open);
              $end_fmin_timer = microtime();
              $total_fmin_timer = $start_min_timer - $end_min_timer;
              mail("[email protected]", "Five Minute Cron was run.", "The five minute cron was run succesfully.\r\n" . "Time: $time\r\n" . "Time Took: $start_fmin_timer - $end_fmin_timer\r\n" . "Total: $total_fmin_timer.", "From: [email protected]");
          }
      }
  }
  
  if ($time - $last_hour_run >= $cron_hor_run) {
      $start_hour_timer = microtime();
      if ($time - $last_hour_run / 60 > 1) {
          $hour_run_no = $time - $last_hour_run / 60;
      } else {
          $hour_run_no = 1;
      }
      for ($i = 0; $i < $hour_run_no; $i++) {
          mysql_query("UPDATE gangs SET gangCHOURS=gangCHOURS-1 WHERE gangCRIME>0", $c);
          $q = mysql_query("SELECT g.*,oc.* FROM gangs g LEFT JOIN orgcrimes oc ON g.gangCRIME=oc.ocID WHERE g.gangCRIME > 0 AND g.gangCHOURS = 0", $c);
          while ($r = mysql_fetch_array($q)) {
              $suc = rand(0, 1);
              if ($suc) {
                  $log = $r['ocSTARTTEXT'] . $r['ocSUCCTEXT'];
                  $muny = (int)(rand($r['ocMINMONEY'], $r['ocMAXMONEY']));
                  $log = str_replace(array("{muny}", "'"), array($muny, "''"), $log);
                $do = mysql_query("UPDATE gangs SET gangMONEY=gangMONEY+$muny,gangCRIME=0 WHERE gangID={$r['gangID']}", $c);
                  mysql_query("INSERT INTO oclogs VALUES ('',{$r['ocID']},{$r['gangID']}, '$log', 'success', $muny, '{$r['ocNAME']}', unix_timestamp())", $c);
                  $i = mysql_insert_id($c);
                  $qm = mysql_query("SELECT * FROM users WHERE gang={$r['gangID']}", $c);
                  while ($rm = mysql_fetch_array($qm)) {
                      event_add($rm['userid'], "Your Gang's Organised Crime Succeeded. Go <a href='oclog.php?ID=$i'>here</a> to view the details.", $c);
                  }
              } else {
                  $log = $r['ocSTARTTEXT'] . $r['ocFAILTEXT'];
                  $muny = 0;
                  $log = str_replace(array("{muny}", "'"), array($muny, "''"), $log);
                  mysql_query("UPDATE gangs SET gangCRIME=0 WHERE gangID={$r['gangID']}", $c);
                  mysql_query("INSERT INTO oclogs VALUES ('',{$r['ocID']},{$r['gangID']}, '$log', 'failure', $muny, '{$r['ocNAME']}', unix_timestamp())", $c);
                  $i = mysql_insert_id($c);
                  $qm = mysql_query("SELECT * FROM users WHERE gang={$r['gangID']}", $c);
                  while ($rm = mysql_fetch_array($qm)) {
                      event_add($rm['userid'], "Your Gang's Organised Crime Failed. Go <a href='oclog.php?ID=$i'>here</a> to view the details.", $c);
                  }
              }
          }
          
          if (empty($do)) {
              mail("[email protected]", "Hour Cron not run.", "The hour cron could not run because of a mysql error.", "From: [email protected]");
          } else {
              $open = fopen("crons/cron_fiveminute.txt", "w");
              fputs($open, time());
              fclose($open);
              $end_hour_timer = microtime();
              $total_hour_timer = $start_min_timer - $end_min_timer;
              mail("[email protected]", "Hour Cron was run.", "The hour cron was run succesfully.\r\n" . "Time: $time\r\n" . "Time Took: $start_hour_timer - $end_hour_timer\r\n" . "Total: $total_hour_timer.", "From: [email protected]");
          }
      }
  }
  
  if ($time - $last_day_run >= $cron_day_run) {
      $start_day_timer = microtime();
      if ($time - $last_day_run / 60 > 1) {
          $day_run_no = $time - $last_day_run / 60;
      } else {
          $day_run_no = 1;
      }
      for ($i = 0; $i < $day_run_no; $i++) {
          mysql_query("UPDATE users SET shots=6");
          mysql_query("UPDATE users SET daysingang=daysingang+1 WHERE gang > 0", $c);
       $do = mysql_query("UPDATE users SET daysold=daysold+1", $c);
          mysql_query("UPDATE users SET mailban=mailban-1 WHERE mailban > 0", $c);
          mysql_query("UPDATE users SET donatordays=donatordays-1 WHERE donatordays > 0", $c);
          mysql_query("UPDATE users SET cdays=cdays-1 WHERE course > 0", $c);
          mysql_query("UPDATE users SET bankmoney=bankmoney+(bankmoney/50) where bankmoney>0", $c);
          mysql_query("UPDATE users SET cybermoney=cybermoney+(cybermoney/100*7) where cybermoney>0", $c);
          $q = mysql_query("SELECT * FROM users WHERE cdays=0 AND course > 0", $c);
          while ($r = mysql_fetch_array($q)) {
              $cd = mysql_query("SELECT * FROM courses WHERE crID={$r['course']}", $c);
              $coud = mysql_fetch_array($cd);
              $userid = $r['userid'];
              mysql_query("INSERT INTO coursesdone VALUES({$r['userid']},{$r['course']})", $c);
              $upd = "";
              $ev = "";
              if ($coud['crSTR'] > 0) {
                  $upd .= ",us.strength=us.strength+{$coud['crSTR']}";
                  $ev .= ", {$coud['crSTR']} strength";
              }
              if ($coud['crGUARD'] > 0) {
                  $upd .= ",us.guard=us.guard+{$coud['crGUARD']}";
                  $ev .= ", {$coud['crGUARD']} guard";
              }
              if ($coud['crLABOUR'] > 0) {
                  $upd .= ",us.labour=us.labour+{$coud['crLABOUR']}";
                  $ev .= ", {$coud['crLABOUR']} labour";
              }
              if ($coud['crAGIL'] > 0) {
                  $upd .= ",us.agility=us.agility+{$coud['crAGIL']}";
                  $ev .= ", {$coud['crAGIL']} agility";
              }
              if ($coud['crIQ'] > 0) {
                  $upd .= ",us.IQ=us.IQ+{$coud['crIQ']}";
                  $ev .= ", {$coud['crIQ']} IQ";
              }
              $ev = substr($ev, 1);
              if ($upd) {
                  mysql_query("UPDATE users u LEFT JOIN userstats us ON u.userid=us.userid SET us.userid=us.userid $upd WHERE u.userid=$userid", $c) or die(mysql_error() . "<br />" . "UPDATE users u LEFT JOIN userstats us ON u.userid=us.userid SET us.userid=us.userid $upd WHERE u.userid=$userid");
              }
              mysql_query("INSERT INTO events VALUES('',$userid,unix_timestamp(),0,'Congratulations, you completed the {$coud['crNAME']} and gained $ev!')", $c);
          }
          mysql_query("UPDATE users SET course=0 WHERE cdays=0", $c);
          mysql_query("TRUNCATE TABLE votes;", $c);
          mysql_query("UPDATE fedjail set fed_days=fed_days-1", $c);
          mysql_query("UPDATE users u LEFT JOIN fedjail f ON u.fedjail=f.fed_id SET u.fedjail=0 WHERE f.fed_days=0", $c);
          mysql_query("DELETE FROM fedjail WHERE fed_days=0", $c);
          mysql_query("UPDATE users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN jobs j ON j.jID=u.job LEFT JOIN jobranks jr ON u.jobrank=jr.jrID SET u.money=u.money+jr.jrPAY,us.strength=us.strength+jr.jrSTRG,us.labour=us.labour+jr.jrLABOURG,us.IQ=us.IQ+jr.jrIQG,u.exp=u.exp+(jr.jrPAY/20) WHERE u.job > 0 AND u.jobrank > 0", $c) or die("UPDATE users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN jobs j ON j.jID=u.job LEFT JOIN jobranks jr ON u.jobrank=jr.jrID SET u.money=u.money+jr.jrPAY,us.strength=us.strength+jr.jrSTRG,us.labour=us.labour+jr.jrLABOURG,us.IQ=us.IQ+jr.jrIQG WHERE u.job > 0 AND u.jobrank > 0<br />" . mysql_error());
          mysql_query("update users set turns=200 WHERE donatordays>=1", $c) or die(mysql_error());
          mysql_query("update users set turns=100 WHERE donatordays<=0", $c) or die(mysql_error());
          
          if (empty($do)) {
              mail("[email protected]", "Day Cron not run.", "The hour cron could not run because of a mysql error.", "From: [email protected]");
          } else {
              $open = fopen("crons/cron_fiveminute.txt", "w");
              fputs($open, time());
              fclose($open);
              $end_day_timer = microtime();
              $total_day_timer = $start_min_timer - $end_min_timer;
              mail("[email protected]", "Day Cron was run.", "The day cron was run succesfully.\r\n" . "Time: $time\r\n" . "Time Took: $start_day_timer - $end_day_timer\r\n" . "Total: $total_day_timer.", "From: [email protected]");
          }
      }
  }
  
  exit;
?>

Link to comment
https://forums.phpfreaks.com/topic/63011-a-unusual-error/#findComment-313818
Share on other sites

I think you might need a bit more of file_get_contents() and a bit less of file();

The former returns a string of the data from the file, the latter an array of the lines in the file.

To be honest, you shouldn't be using individual files for individual values on scripts which expect heavy usage- it would be better to combine the values on different lines of the same file, or in the DB, if it's possible.

Link to comment
https://forums.phpfreaks.com/topic/63011-a-unusual-error/#findComment-313841
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.