Jump to content
xisto Community
Feelay

Unsupported Operand Types In / What this =?

Recommended Posts

Hey!

 

Can anyone try to help me find what I've made wrong =? I keep getting this error (Fatal error: Unsupported operand types in /home/feelay/public_html/attackck.php on line 49)

But I can't find what I've made wrong =/

 

Here is the code:

 

<?phpsession_start();include "database.php";############################################################	function attack(){ #Line 10				#Ge $dbQueryHealth ett värde 		$atkuser= mysql_real_escape_string($_POST['atkuser']);$querythe =("SELECT temphealth FROM characters WHERE user='$atkuser'")or die(mysql_error());			#Sätt $currentHealth med värdet frün databas-resursen $dbQuery 		if(mysql_num_rows(mysql_query($querythe)) == 1)	{		$currentHealthEnemy = mysql_fetch_assoc(mysql_query($querythe));		}else{ die("User Don't Excist. Please Go Back And Try Again");}#Line 20					 					 $nuser=mysql_real_escape_string($_SESSION['user']);$auser=mysql_real_escape_string($_SESSION['admin']);if($nuser){$userfinal=$nuser;}elseif($auser){$userfinal=$auser;#Line 30}		####################################################$querythy ="SELECT temphealth FROM characters WHERE user='$userfinal'"or die(mysql_error());				#Sätt $currentHealth med värdet frün databas-resursen $dbQuery 		$currentHealthYou = mysql_result(mysql_query($querythy),0)or die(mysql_error());  #Line 40  		 	   $minHealth = 0;	   $maxHealth = 100;	   $expAward = mt_rand (1, 300);	   $healthAward = mt_rand (1, 30);	   $winner= mt_rand (0, 1);#Line 50	if($winner) { 			if(($currentHealthEnemy - $healthAward) > $minHealth) {   				$currentHealthEnemy -= $healthAward;				#$currentExp + expAward;				echo "You won! The enemy now have {$currentHealthEnemy} HP.";  /*Line 60 */			} else { #Line 70			    echo "You won! You Killed The Enemy"; 				$currentHealthEnemy = $maxHealth;				#$currentExp + expAward; 			} 		} else { 			if(($currentHealthYou - $healthAward) <= 0) { 				echo "You Lost. The Enemy killed you."; 				$currentHealthYou = 100; 			} else { #Line 80		$currentHealthYou -= $healthAward; 				echo "You lost! You've lost {$healthAward} HP. You now have {$currentHealthYou} HP."; 			}  		}$nuser=mysql_real_escape_string($_SESSION['user']);$auser=mysql_real_escape_string($_SESSION['admin']);if($nuser){#Line 90$userfinal=$nuser;}elseif($auser){$userfinal=$auser;}	$SeUs = $userfinal;$PoUS = mysql_real_escape_string($_POST['atkuser']);$result = mysql_query("UPDATE characters SET temphealth='$currentHealthYou' WHERE user='$SeUs'") or die(mysql_error());#Line 100$result = mysql_query("UPDATE characters SET temphealth='$currentHealthEnemy' WHERE user='$PoUS'") or die(mysql_error());		#mysql_query ("UPDATE characters SET exp = \"{$currentExp}\" WHERE user =".$_SESSION['user']."");   	} echo attack();#Line 110mysql_close();?><form action="index.php" method="post"><input type="submit" name="home" value="Back to home">

Thanks for your help

 

//Feelay

Share this post


Link to post
Share on other sites

This is driving me mad too haha... But then again it's a bit tricky without actually having the database. The only thing I can think of right now is that there's an empty query somewhere. A query may be empty is syntax is off, rather than undefined.. This would cause the die() not to execute. So then perhaps mysql_result is thrown off and then it calls an error slightly after (PHP sometimes calls an error a few lines after the error has actually occured.. at least for me haha).- Jared

Share this post


Link to post
Share on other sites

Hey Freelay,

This section here:

#Line 50  if ( $winner ) {	if ( ( $currentHealthEnemy - $healthAward ) > $minHealth ) {	  $currentHealthEnemy -= $healthAward;	  // $currentExp + expAward;	  echo 'You won! The enemy now have ' . $currentHealthEnemy . 'HP';

Confuses me with the operand -= which is the assignment by subtraction, but as far as I know, I've only used this in C++ and don't know if it was carried on over to PHP.

So you may have to do:

$currentHealthEnemy = $currentHealthEnemy - $healthAward;

Cheers,

MC

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.