简体   繁体   中英

Php code returns blank page

I have code:

function Rotuse($building){
  global $lang, $wg_village, $db;
  $village_id=$wg_village->id;
  includelang("musu"); 
  $parse=$lang; 
  $rs1zn=6400;
  $rs2zn=6650;
  $rs3zn=5940;
  $rs4zn=1340;
  $parse["rs1"]=$rs1zn;
  $parse["rs2"]=$rs2zn;
  $parse["rs3"]=$rs3zn;
  $parse["rs4"]=$rs4zn;

  if(isset($_POST['uzsakyti1'])){
    if($wg_village->rs1>=$rs1zn && $wg_village->rs2>=$rs2zn && $wg_village->rs3>=$rs3zn && $wg_village->rs4>=$rs4zn){

      $sql="UPDATE wg_villages SET rs1=rs1-$rs1zn, rs2=rs2-$rs2zn, rs3=rs3-$rs3zn, rs4=rs4-$rs4zn WHERE id=$village_id";
      $db->setQuery($sql);
      $db->query();
      if($db->getAffectedRows()==0)
      {
        globalError2("function changeRSVillage:".$sql);
      }
      echo ".$village_id.- .$wg_village.";
    }
    else{
      echo "You don't have enought resources!";
    }
  }
  $rs1azn=29700;
  $rs2azn=33250;
  $rs3azn=32000;
  $rs4azn=6700;
  $parse["rs1a"]=$rs1azn;
  $parse["rs2a"]=$rs2azn;
  $parse["rs3a"]=$rs3azn;
  $parse["rs4a"]=$rs4azn;

  $parse['id']=$building->index;
  return parsetemplate(gettemplate('rotuse_body'), $parse);
}

And when I press post button it returns blank page but function works, problem is in here:

echo ".$village_id.- .$wg_village.";

maybe I should add something like this:

return parsetemplate(gettemplate('rotuse_body'), $parse);

I don't know what I'm doing wrong, I mean function works how I want but only problem that it returns blank page. So if anybody could point me out where is the problem it would be great!

EDIT NR1: VAR DUMP OF $village_id and $wg_village

string(5) "80784" object(stdClass)#25 (35) { ["id"]=> string(5) "80784" ["name"]=> string(7) "NewName" ["x"]=> string(3) "-99" ["y"]=> string(3) "-14" ["kind_id"]=> string(1) "5" ["user_id"]=> string(1) "1" ["rs1"]=> int(36000) ["rs2"]=> int(36000) ["rs3"]=> int(36000) ["rs4"]=> int(36000) ["workers"]=> string(2) "51" ["troop_keep"]=> string(1) "0" ["time_update_rs1"]=> string(19) "2014-05-09 01:45:30" ["time_update_rs2"]=> string(19) "2014-05-09 01:45:30" ["time_update_rs3"]=> string(19) "2014-05-09 01:45:30" ["time_update_rs4"]=> string(19) "2014-05-09 01:45:30" ["nation_id"]=> string(1) "2" ["merchant_underaway"]=> string(1) "0" ["child_id"]=> string(0) "" ["cp"]=> string(3) "104" ["cpupdate_time"]=> string(19) "2014-05-08 21:49:55" ["krs1"]=> string(1) "1" ["krs2"]=> string(1) "1" ["krs3"]=> string(1) "1" ["krs4"]=> string(1) "1" ["faith"]=> string(1) "3" ["faith_time"]=> string(19) "2014-05-07 22:05:44" ["dateCreate_vila"]=> string(19) "2014-05-05 20:38:26" ["capa123"]=> int(36000) ["capa4"]=> int(36000) ["speedIncreaseRS1"]=> float(1000) ["speedIncreaseRS2"]=> float(600) ["speedIncreaseRS3"]=> float(800) ["speedIncreaseRS4"]=> float(1200) ["speedIncreaseRS4Real"]=> float(1149) }

EDIT nr 2 added error :

Catchable fatal error: Object of class stdClass could not be converted to string in /includes/function_troop.php on line 70

and that line is echo ".$village_id.- .$wg_village.";

Your $wg_village object is the reason.

you can't echo your object with sub-attribute like that.

One of the way to solve the problem is as below:

$hi->a =1;
$hi->b =3;

echo "a=".$hi->a.", b=".$hi->b;

or if you only want to check the content/properties of the object with a probably bad format :

echo print_r($hi);

a better way is to create a method within your class which prints the properties out in the format you want, and then you can do something like:

echo $hi->printPredifinedFormat();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM