Nov 8, 2009

Unsupported Operand Types In / - What this =?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Unsupported Operand Types In / - What this =?

Feelay
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:

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

 

 

 


Comment/Reply (w/o sign-up)

Jared
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

Comment/Reply (w/o sign-up)

mastercomputers
Hey Freelay,

This section here:

CODE
#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:

CODE
$currentHealthEnemy = $currentHealthEnemy - $healthAward;


Cheers,

MC

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Unsupported Operand Types


    Looking for unsupported, operand, types,

See Also,

*SIMILAR VIDEOS*
Searching Video's for unsupported, operand, types,
advertisement



Unsupported Operand Types In / - What this =?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com