Max Levels Issue
Posted: Tue Mar 04, 2014 10:23 pm
Okay, I have it to where the player can purchase so many gunmen per level, and it works fine for the gunmen, but for some reason, the guards are not letting it work. It allows one to go over the max amount of guards one can purchase per level. I'm sure I"m just missing something little in the code, but I just can't find it. Any help would be great.
Code For Working Max Gunmen
Code For Non-Working Guards:
Form For Both Gunmen and Guards:
Code For Working Max Gunmen
Code: Select all
<?php
//user buys a unit Gunmen//
if(isset($_POST['train'])){
$henchmen = protect($_POST['henchmen']);
$food_needed = ((30) * $henchmen);
if($henchmen == 0){
echo '<span id="errormess"><big><font color="red"><b>You must purchase a positive amount!</b></font></span></big>';
}elseif($henchmen > 5){
echo '<span id="errormess"><big><font color="red"><b>You can only purchase 5 at a time!</b></font></span></big>';
}elseif($henchmen < 5){
echo '<span id="errormess"><big><font color="red"><b>You can only purchase 5 at a time!</b></font></span></big>';
}elseif($stats_food < $food_needed){
echo '<span id="errormess"><big><font color="red"><b>You do not have enough food!</b></font></span></big>';
}else{
$maxpurchase = $stats_level * 25;
$inventorylimit = $maxpurchase;
if($unit_gunmen == $inventorylimit){
echo '<span id="errormess"><big><font color="red"><b>You may only purchase 25 per level!</b></font></span></big>';
}else{
$unit_gunmen += $henchmen;
$update_gunmen = "UPDATE `unit` SET `henchmen`='".$unit_gunmen."' WHERE `id`='".$_SESSION['userid']."'";
$user_query1 = mysqli_query($db_conx, $update_gunmen);
$stats_food -= $food_needed;
$update_food = "UPDATE `stats` SET `food`='".$stats_food."' WHERE `id`='".$_SESSION['userid']."'";
$user_query = mysqli_query($db_conx, $update_food);
include("update_stats.php");
echo '<span id="errormess"><big><font color="red"><b>You have purchased Gunmen!</b></font></span></big>';
}
}
}
Code: Select all
<?PHP
//user buys unit Guards//
if(isset($_POST['train1'])){
$guards = protect($_POST['guards']);
$food_needed = ((30) * $guards);
if($guards == 0){
echo '<span id="errormess"><big><font color="red"><b>You must purchase a positive amount!</b></font></span></big>';
}elseif($guards > 5){
echo '<span id="errormess"><big><font color="red"><b>You can only purchase 5 at a time!</b></font></span></big>';
}elseif($guards < 5){
echo '<span id="errormess"><big><font color="red"><b>You can only purchase 5 at a time!</b></font></span></big>';
}elseif($stats_food < $food_needed){
echo '<span id="errormess"><big><font color="red"><b>You do not have enough food!</b></font></span></big>';
}else{
$maxpurchase = $stats_level * 25;
$inventorylimit = $maxpurchase;
if($unit_guards == $inventorylimit){
echo '<span id="errormess"><big><font color="red"><b>You may only purchase 25 per level!</b></font></span></big>';
}else{
$unit_guards += $guards;
$update_guards = "UPDATE `unit` SET `guards`='".$unit_guards."' WHERE `id`='".$_SESSION['userid']."'";
$user_query = mysqli_query($db_conx, $update_guards);
$stats_food -= $food_needed;
$update_food = "UPDATE `stats` SET `food`='".$stats_food."' WHERE `id`='".$_SESSION['userid']."'";
$user_query = mysqli_query($db_conx, $update_food);
include("update_stats.php");
echo '<span id="errormess"><big><font color="red"><b>You have purchased Guards!</b></font></span></big>';
}
}
}
?>
Code: Select all
<center> <form action="units.php" method="post">
<center><h2>Train Units</h2></center>
<table cellspacing="0" border="3" bordercolor="grey" width="99%">
<tr style="background-color:black;" align="center">
<td class = "tooltip" style=" border-right: 1px solid white;">Gunmen<img src="images/infoicon.png" width = "30"><span>Purchasing Gunmen will increase your attack.<br>You should have a gun for each<br>gunmen you own! </span></td>
<td class = "tooltip" style=" border-right: 1px solid white;">Guards<img src="images/infoicon.png" width = "30"><span>Purchasing Guards will increase your defense.<br>You should have a vest for each<br>guard you own! </span></td>
</tr>
<tr style="background-color:black;" align="center">
<td style=" border-right: 1px solid white;"><img src="theme/henchmen.png" width="75" height="75"></td>
<td><img src="theme/guards.png" width="75" height="75"></td>
</tr>
<tr style="background-color:black;" align="center">
<td style=" border-right: 1px solid white;">You Own: <?php echo number_format($unit_gunmen); ?></td>
<td>You Own: <?php echo number_format($unit_guards); ?></td>
</tr>
<tr style="background-color:black;" align="center">
<td style=" border-right: 1px solid white;"><img src="http://bit.ly/14ngtSd" width="20" height="20"><font color="yellow">30</font> <input type="text" name="henchmen" placeholder="5 at a time" maxlength="1" size="7"/></td>
<td><img src="http://bit.ly/14ngtSd" width="20" height="20"><font color="yellow">30</font> <input type="text" name="guards" placeholder="5 at a time" maxlength="1" size="7"/></td>
</tr>
<tr style="background-color:black;" align="center">
<td style=" border-right: 1px solid white;"><input type="submit" name="train" value="Buy Gunmen"/> </td>
<td><input type="submit" name="train1" value="Buy Guards"/> </td>
</tr>
</table></form>