Jump to content

[SOLVED] Fatal error: Unsupported operand types in... Please help


feelay

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:

 

 

 

<?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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.