Hi im having trouble making it so when a player attacks another the certain unit with subtract the attacking players units but im stuck ive tried several thing but it just wont go through and I dont know php too well but know even if a comma is missing then things wont work right. here is the code where it updates the players info. any help would be greatly appreciated.
//Query
if ($winner_id == $player_id) {
$log_fight = mysqli_query($mysqli, "INSERT INTO `fights` (playera_id, playerb_id, winner_id, date, time)
VALUES ('$player_id', '$opponent_id', '$winner_id', '$date', '$time')");
$player_update = mysqli_query($mysqli, "UPDATE `players` SET money=money+500, gold=gold+2, energy=energy-10, health=health-5, respect=respect+325 WHERE id='$player_id'");
$opponent_update = mysqli_query($mysqli, "UPDATE `players` SET money=money-250, health=health-10 WHERE id='$opponent_id'");
$content = '' . $rowu['username'] . ' challenged you to fight and you lost the fight. You lost $250.';
$message = mysqli_query($mysqli, "INSERT INTO `messages` (fromid, toid, date, time, content)
VALUES ('$player_id', '$opponent_id', '$date', '$time', '$content')");
echo '
<div class="alert alert-success">
<center><strong><i class="fa fa-trophy"></i> You won the fight against this player. <br />Reward: <span class="badge bg-success">$ 500</span> and <span class="badge bg-warning">2 Gold</span></strong></center>
</div>';
} else {
$log_fight = mysqli_query($mysqli, "INSERT INTO `fights` (playera_id, playerb_id, winner_id, date, time)
VALUES ('$player_id', '$opponent_id', '$winner_id', '$date', '$time')");
$player_update = mysqli_query($mysqli, "UPDATE `players` SET money=money-250, energy=energy-10, health=health-10 WHERE id='$player_id'");
$opponent_update = mysqli_query($mysqli, "UPDATE `players` SET money=money+500, gold=gold+2, health=health-5, respect=respect+325 WHERE id='$opponent_id'");
$content = '' . $rowu['username'] . ' challenged you to fight and you won the fight. You earned $500 and 2 gold.';
$message = mysqli_query($mysqli, "INSERT INTO `messages` (fromid, toid, date, time, content)
VALUES ('$player_id', '$opponent_id', '$date', '$time', '$content')");
echo '
<div class="alert alert-danger">
<center><strong><i class="fa fa-trophy"></i> You lost the fight against this player</strong></center>
</div>';
}
}
}
?>