I'm trying to create a browser based rpg game, the goal of this particular script is to handle the competition, take the attackers damage, and subtract it from the defenders health, and take the return damage that the defender deals, and subtract that from the attackers health.
I assume the problem that I am having is in this section of code (I'll post the whole page at the end of this post)
$db-> query("SELECT * FROM LadderChamp.users WHERE Username='$attacker'");
$health = $col['Health'];
echo "<br>";
echo $health;
$health -= $ddmg;
echo "<br>";
echo $health;
mysql_query("UPDATE LadderChamp.users SET Health='$health' WHERE Username='$attacker'");
$db-> query("SELECT * FROM LadderChamp.users WHERE Username='$defender'");
$health = $col['Health'];
echo "<br>";
echo $health;
$health -= $dmg;
echo "<br>";
echo $health;
mysql_query("UPDATE LadderChamp.users SET Health='$health' WHERE Username='$defender'");
Both the attacker and defender start with 1000 life, and after the original running of the script they both end with 850 and 575 respectively, but when I rerun the script, to simulate a second attack, both healths become 850 before the damage is dealt.
Alone the first half of that works perfectly, but when I run the second half of it alone the health never remains set to the final health, ever time I rerun the script, the health goes back up to 1000 before the damage is dealt.
the full script is:
<?php
session_start();
require("./heroes/wizard.php");
$db = new Database();
$result = $db-> query('SELECT * FROM LadderChamp.combat');
$issue = $db-> query('SELECT * FROM LadderChamp.users');
$row = mysql_fetch_array($result);
$col = mysql_fetch_array($issue);
$attacker = $_SESSION['Username'];
$defender = "cody";
$dmg = 0;
$tdmg = 0;
$ddmg = 0;
$db-> query("SELECT * FROM LadderChamp.combat WHERE Username='$attacker'");
$attack = $row['Attack'];
$dmg = $attack($dmg, $tdmg);
$db-> query("SELECT * FROM LadderChamp.combat WHERE Username='$defender'");
$defense = $row['Defense'];
$ddmg = $defense($ddmg, 0);
//$tdmg = $defense(0, $dmg);
$db-> query("SELECT * FROM LadderChamp.users WHERE Username='$attacker'");
$health = $col['Health'];
echo "<br>";
echo $health;
$health -= $ddmg;
echo "<br>";
echo $health;
mysql_query("UPDATE LadderChamp.users SET Health='$health' WHERE Username='$attacker'");
$db-> query("SELECT * FROM LadderChamp.users WHERE Username='$defender'");
$health = $col['Health'];
echo "<br>";
echo $health;
$health -= $dmg;
echo "<br>";
echo $health;
mysql_query("UPDATE LadderChamp.users SET Health='$health' WHERE Username='$defender'");
?>