Not Recognizing Rows
Posted: Tue Oct 14, 2014 2:55 am
Okay, everything is working great up until the end when it it to check the row hpoints in the database. It should check to see if the row is equal or less than 0, but it's completely skipping that part. I don't see where I have written anything out of order, but maybe someone here can. I need to know why it skips checking the health and why it doesn't echo out that they have died... The database will go negative in the row hpoints, but it's not recognizing it in the php.
Code: Select all
if (isset($_POST['dropdown'])) {
// cast to integer to avoid malicious values
$dropdown = (int)$_POST['dropdown'];
$rand_num = rand(100,200);
$atk_player = ($rand_num /100) * $_POST['dropdown'] - $attack_user['defense'];
$atk_player2 = number_format($atk_player);
if($_POST['dropdown'] < 1 || $_POST['dropdown'] > 20){
echo '<span id="errormess"><big><center><font color="red"><b>Only between 1 and 20</b></font></span></big><br><br>';
exit;
}elseif($_POST['dropdown'] > $row['bullets']){
echo '<br><span id="errormess"><big><center><font color="red"><b>You do not have enough Bullets!</b></font></span></big><br><br>';
exit;
}elseif($id == $_SESSION['userid']){
echo '<br><span id="errormess"><big><center><font color="red"><b>You cannot attack yourself!</b></font></span></big><br><br>';
exit;
}elseif ($row['bullets'] <= 0) {
echo '<span id="errormess"><big><center><font color="red"><b>You do not have any bullets!</b></font></span></big><br><br>';
exit;
}elseif ($row['bullets'] < $_POST['dropdown']) {
echo '<span id="errormess"><big><center><font color="red"><b>You do not have enough bullets!</b></font></span></big><br><br>';
exit;
}if ($atk_player2 > 0) {
$num = 0 + $atk_player2;
$outputList .= '<b>Your battle has begun! </b>';
$outputList1 .= '<b>You have won the battle! </b>';
$outputList2 .= '<b>You have taken ' . $num . ' health from ' .$attack_user['username']. '</b>';
$outputList3 .= '<b>' .$_POST['dropdown']. ' bullets have been removed from your inventory! </b>';
$outputList5 .= '<b>Your battle has ended! </b>';
$updatehpoints = "UPDATE users SET hpoints=hpoints - $atk_player2 WHERE `id`='".$id."'";
$query = mysqli_query($db_conx, $updatehpoints);
$updatebullets = "UPDATE users SET bullets=bullets - $_POST[dropdown] WHERE id = '$_SESSION[userid]'";
$query = mysqli_query($db_conx, $updatebullets);
}else{
$num = 0 - $atk_player2;
$outputList .= '<b>Your battle has begun! </b>';
$outputList1 .= '<b>You lost the battle! </b>';
$outputList2 .= '<b>You have lost ' . $atk_player2 . ' health ' . '</b>';
$outputList3 .= '<b>You gave ' . $num . ' health to ' .$attack_user['username']. '</b>';
$outputList4 .= '<b>' .$_POST['dropdown']. ' bullets have been removed from your inventory! </b>';
$updatehpoints = "UPDATE users SET hpoints=hpoints - $atk_player2 WHERE `id`='".$id."'";
$query = mysqli_query($db_conx, $updatehpoints);
$updatebullets = "UPDATE users SET bullets=bullets - $_POST[dropdown] WHERE id = '$_SESSION[userid]'";
$query = mysqli_query($db_conx, $updatebullets);
}if ($row['hpoints'] <= 0) {
$outputList6 .= '<b>Your have died! </b>';
}else{
$outputList5 .= '<b>Your battle has ended! </b>';
$updatehpoints = "UPDATE users SET hpoints=hpoints + $atk_player2 WHERE id = '$_SESSION[userid]'";
$query = mysqli_query($db_conx, $updatehpoints);
}
}