Page 1 of 1

Fatal error: Call to a member function on a non-object in

Posted: Mon Feb 05, 2007 8:32 pm
by netpants
Ok, I have a Browser Based RPG. In the RPG you can upgrade your Mine level upgrade.php which will than add +1 to uMineLevel in the database. I have edited the upgrade.php file into upgradeMoat.php and added a field to the user database called uMoatLevel, so When you go to upgradeMoat.php and purchase it it will update the Database +1 to the uMoatLevel and then add some to the uDefense field because a Moat as we all know is meant to be defense for a castle :) So...everything is working fine with the upgradeMoat.php on its own. It takes away the proper amount of gold, adds +1 to the database were supposed to be , and adds defense. But I want to include the upgradeMoat.php into the upgrade.php so its all on one upgrade page. Below you will find the code.

upgrade.php

Code: Select all

<?


$isadmin="*";
include("../includes/inc-header.php");

if($user['uMineLevel']==1){
	$price = 2500000;
}
elseif($user['uMineLevel']==2){
	$price = 7500000;
}
elseif($user['uMineLevel']==3){
	$price = 22500000;
}
elseif($user['uMineLevel']==4){
	$price = 67500000;
}
elseif($user['uMineLevel']==5){
	$price = "-";
	$isupgrades = 1;
}
if($user['uMineLevel']!=5){
	$nextlevel = $user['uMineLevel']+1;
}
if(!$_POST['mine']){
	if(!$isupgrades){
		?>

		<form action="upgrade.php" method="post">
		<?
	}
	?>
	<table width="100%"  border="0">
	  <tr>
		<td colspan="3" class="bodycell3">Upgrades</td>
	  </tr>
	  <tr>
		<td class="bodycell5" align="center" width="30%">
		<b>Mine Level</b>
		</td>
		<td class="bodycell5" align="center" width="40%">
		<?=$price?>
		</td>
		<td class="bodycell5" align="center" width="30%">
		<?
		if($user['uMineLevel']!=5){
			?>
			<input name="mine" type="submit" value="Upgrade to Level <?=$nextlevel?>">
			<?
		}
		else{
			echo "-";
		}
		?>
		</td>
	  </tr>
	</table>

	<?
	if(!$isupgrades){
		?>
		</form>
		<?
	}
}
elseif($_POST['mine']){
	?>
	<table width="100%"  border="0">
	  <tr>
		<td class="bodycell3">Bank</td>
	  </tr>
	  <tr>
		<td class="bodycell4" align="center">
		<?
		if($nextlevel=="-"){
			echo "There are no further upgrades for this.";
		}
		elseif($price>$user['uGold']){
			echo "You don't have enough gold to upgrade.";
		}
		else{
			echo "You successfully upgraded your Mine Level.";
			$db->query("UPDATE users SET uGold=uGold-$price,uMineLevel=$nextlevel WHERE uID='" . $user['uID'] . "'");
		}
		?>
		<br><br>
		<a href="javascript:history.back();">BACK</a>
		</td>
	  </tr>
	</table>
	<?
}
include("../includes/inc-footer.php");
?>
upgradeMoat.php

Code: Select all

<?

$isadmin="*";


if($user['uMoatLevel']==1){
	$Mprice = 2500000;
}
elseif($user['uMoatLevel']==2){
	$Mprice = 7500000;
}
elseif($user['uMoatLevel']==3){
	$Mprice = 22500000;
}
elseif($user['uMoatLevel']==4){
	$Mprice = 67500000;
}
elseif($user['uMoatLevel']==5){
	$Mprice = "-";
	$Misupgrades = 1;
}
if($user['uMoatLevel']!=5){
	$Mnextlevel = $user['uMineLevel']+1;
}
if(!$_POST['moat']){
	if(!$Misupgrades){
		?>
		<form action="upgradeMoat.php" method="post">
		<?
	}
	?>
	<table width="100%"  border="0">
	  <tr>
		<td colspan="3" class="bodycell3">Defense Upgrades</td>
	  </tr>
	  <tr>
		<td class="bodycell5" align="center" width="30%">
		<b>Mine Level</b>
		</td>
		<td class="bodycell5" align="center" width="40%">
		<?=$Mprice?>
		</td>
		<td class="bodycell5" align="center" width="30%">
		<?
		if($user['uMoatLevel']!=5){
			?>
			<input name="mine" type="submit" value="Upgrade to Level <?=$Mnextlevel?>">
			<?
		}
		else{
			echo "-";
		}
		?>
		</td>
	  </tr>
	</table>
	<?
	if(!$Misupgrades){
		?>
		</form>
		<?
	}
}
elseif($_POST['moat']){
	?>
	<table width="100%"  border="0">
	  <tr>
		<td class="bodycell3">Bank</td>
	  </tr>
	  <tr>
		<td class="bodycell4" align="center">
		<?
		if($Mnextlevel=="-"){
			echo "There are no further upgrades for this.";
		}
		elseif($Mprice>$user['uGold']){
			echo "You don't have enough gold to upgrade.";
		}
		else{
			echo "You successfully upgraded your Mine Level.";
			$db->query("UPDATE users SET uGold=uGold-$Mprice,uMoatLevel=$Mnextlevel,uDefense=uDefense+(100000*uMoatLevel) WHERE uID='" . $user['uID'] . "'");
		}
		?>
		<br><br>
		
		</td>
	  </tr>
	</table>
	<?
}

?>
I would appreciate any help on this as When i tried just including the upgradeMoat.php file into the upgrade.php file it worked sort of..

Posted: Mon Feb 05, 2007 10:01 pm
by superdezign
Just using include() or require() will add the code from the included file to wherever it's being included. There may be something about the scope of variables involved, but I doubt it.

Posted: Tue Feb 06, 2007 9:31 am
by netpants
See I tried the include() and it works sort of, but I think it gets mixed up with the code from upgrade.php

Posted: Tue Feb 06, 2007 9:52 am
by netpants
i see my problem falling into the depths of the DeVNetwork never to be solved.

Posted: Tue Feb 06, 2007 9:58 am
by netpants
I get this error when including it.

Code: Select all

Bank
You successfully upgraded your Moat Level.
Fatal error: Call to a member function on a non-object in /home/gamesite/domains/mygamespot.net/public_html/battle/play/upgradeMoat.php on line 97

Here is the upgrade.php with the upgradeMoat.php included into it.

Code: Select all

<?
$isadmin="*";
include("../includes/inc-header.php");

if($user['uMineLevel']==1){
	$price = 2500000;
}
elseif($user['uMineLevel']==2){
	$price = 7500000;
}
elseif($user['uMineLevel']==3){
	$price = 22500000;
}
elseif($user['uMineLevel']==4){
	$price = 67500000;
}
elseif($user['uMineLevel']==5){
	$price = "-";
	$isupgrades = 1;
}
if($user['uMineLevel']!=5){
	$nextlevel = $user['uMineLevel']+1;
}
if(!$_POST['mine']){
	if(!$isupgrades){

		?>
------------------INCLUDED RIGHT HERE----------------------------
<?
include("upgradeMoat.php");
?>
-------------------------------------------------------------------------
		<form action="upgrade.php" method="post">
		<?
	}
	?>
	<table width="100%"  border="0">
	  <tr>
		<td colspan="3" class="bodycell3">Upgrades</td>
	  </tr>
	  <tr>
		<td class="bodycell5" align="center" width="30%">
		<b>Mine Level</b>
		</td>
		<td class="bodycell5" align="center" width="40%">
		<?=$price?>
		</td>
		<td class="bodycell5" align="center" width="30%">
		<?
		if($user['uMineLevel']!=5){
			?>
			<input name="mine" type="submit" value="Upgrade to Level <?=$nextlevel?>">
			<?
		}
		else{
			echo "-";
		}
		?>
		</td>
	  </tr>
	</table>

	<?
	if(!$isupgrades){
		?>
		</form>
		<?
	}
}
elseif($_POST['mine']){
	?>
	<table width="100%"  border="0">
	  <tr>
		<td class="bodycell3">Bank</td>
	  </tr>
	  <tr>
		<td class="bodycell4" align="center">
		<?
		if($nextlevel=="-"){
			echo "There are no further upgrades for this.";
		}
		elseif($price>$user['uGold']){
			echo "You don't have enough gold to upgrade.";
		}
		else{
			echo "You successfully upgraded your Mine Level.";
			$db->query("UPDATE users SET uGold=uGold-$price,uMineLevel=$nextlevel WHERE uID='" . $user['uID'] . "'");
		}
		?>
		<br><br>
		<a href="javascript:history.back();">BACK</a>
		</td>
	  </tr>
	</table>
	<?
}
include("../includes/inc-footer.php");
?>