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

