Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Unsupported Operand Types In /, What this =?
Feelay
post Feb 4 2008, 11:37 AM
Post #1


Kinda N00B
Group Icon

Group: Members
Posts: 230
Joined: 13-January 08
From: Sweden
Member No.: 27,579



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
Go to the top of the page
 
+Quote Post
Jared
post Apr 19 2008, 08:17 AM
Post #2


Member [ Level 1 ]
Group Icon

Group: [HOSTED]
Posts: 40
Joined: 17-April 08
Member No.: 29,853



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
Go to the top of the page
 
+Quote Post
mastercomputers
post May 1 2008, 01:44 AM
Post #3


PESTICIDAL MANIAC
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Help: $_post Variable For Options From Select Types?(6)


 



- Lo-Fi Version Time is now: 2nd December 2008 - 12:14 AM