problem with math and adding numbers to the database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xwhitchx
Forum Commoner
Posts: 38
Joined: Mon Jun 21, 2010 4:30 pm

problem with math and adding numbers to the database

Post by xwhitchx »

so this is my attack code, it looks like it works but no matter how much damage you do it will kill the other player. so if i do 0 dmg to some one with 10 hp it was say i did 0 and i have it echo out how much hp they still has. that all works fine but when i go to the next page all there hp is gone.... i dont understand y it is doing this.


Code: Select all

if ($_GET['att']=='Attack')

{

$att=ceil($user1luk*$user1dex*$user1str/4+$user1int/4+3);

$defend=ceil($user2luk*$user2dex+$user2int/3);

$outcome=ceil($att-$defend);

//-----------------------------------------

 

$attdamage= mysql_query("SELECT * FROM users WHERE username='$getusername'");

while($row3 = mysql_fetch_array($attdamage))

  {

  $user2hp= $row3['hp'];

 

 

  if ($outcome<0)

  {

  $outcome=0;

  }

 

  else{

    $outcome=$outcome;

  }

 

 

  $user2suphp= $user2hp - $outcome;

 

 

 

 

  $newhp= mysql_query('UPDATE users SET hp= "\''.$user2suphp.'\'" WHERE username=\''.$row3['username'].'\'');

 

 }

 

 

 //text-----------------------

if($user2suphp==1 || $user2suphp>0)

 {

 echo'You did '.$outcome.' Damage to '.$getusername.'<br/>';

 echo  $outcome.'<br/>';

 echo $user2suphp.'<br/>';

 echo $newhp.'<br/>';

 

 }

 else

 {

 

  echo'You did '.$outcome.' Damage to '.$getusername;

 echo'you have killed '.$getusername.'<br/>';

 

 

 }
Post Reply