feelay Posted February 4, 2008 Share Posted February 4, 2008 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: <?php session_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 110 mysql_close(); ?> <form action="index.php" method="post"> <input type="submit" name="home" value="Back to home"> Thanks for your help //Feelay Quote Link to comment https://forums.phpfreaks.com/topic/89415-solved-fatal-error-unsupported-operand-types-in-please-help/ Share on other sites More sharing options...
revraz Posted February 4, 2008 Share Posted February 4, 2008 See if removing the space after the 3 mt_rand helps. Quote Link to comment https://forums.phpfreaks.com/topic/89415-solved-fatal-error-unsupported-operand-types-in-please-help/#findComment-457867 Share on other sites More sharing options...
feelay Posted February 5, 2008 Author Share Posted February 5, 2008 It Didn't help =/ Quote Link to comment https://forums.phpfreaks.com/topic/89415-solved-fatal-error-unsupported-operand-types-in-please-help/#findComment-458467 Share on other sites More sharing options...
toplay Posted February 5, 2008 Share Posted February 5, 2008 When posting, please point out what line your error is on so we don't have to guess or count. I assume line 49 is this: if(($currentHealthEnemy - $healthAward) > $minHealth) { Earlier in your code, you assign an array to $currentHealthEnemy: $currentHealthEnemy = mysql_fetch_assoc(mysql_query($querythe)); So, you're trying to subtract a numeric value from the whole of an array....not allowed/possible. Read up on how to properly retrieve data from MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/89415-solved-fatal-error-unsupported-operand-types-in-please-help/#findComment-458472 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.