Page 1 of 1

Error Messages Not Breaking [Resolved]

Posted: Sat Sep 14, 2013 2:51 am
by Epiales
What I mean, is that when I go to purchase a unit, then the error message is doubled. I know it's bypassing the {}'s for some reason and repeating the second on further down, and I don't know why. Anyone have any ideas why it's skipping?

Code: Select all

 //user buys unit gunmen//
    if(isset($_POST['train'])){
        $henchmen = protect($_POST['henchmen']);
        $food_needed = (30 * $henchmen);
        
        if($henchmen < 1){
    echo '<span id="errormess"><big><font color="red"><b>You must train a positive number of units!</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{
            $unit['henchmen'] += $henchmen;          
            $update_business = mysql_query("UPDATE `unit` SET `henchmen`='".$unit['henchmen']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
            $stats['food'] -= $food_needed;
            $update_food = mysql_query("UPDATE `stats` SET `food`='".$stats['food']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
    echo '<span id="errormess"><big><font color="red"><b>You have trained your units!</b></font></span></big>';
    }
}
 //user buys unit guards//
    if(isset($_POST['train'])){
        $guards = protect($_POST['guards']);
        $food_needed = (30 * $guards);
        
        if($guards == 0){
    echo '<span id="errormess"><big><font color="red"><b>You must train a positive number of units!</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{
            $unit['guards'] += $guards;          
            $update_business = mysql_query("UPDATE `unit` SET `guards`='".$unit['guards']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
            $stats['food'] -= $food_needed;
            $update_food = mysql_query("UPDATE `stats` SET `food`='".$stats['food']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
    echo '<span id="errormess"><big><font color="red"><b>You have trained your units!</b></font></span></big>';
   
     } 
 }
Example is that when you press the button without and number in it? It puts the error message twice:

Code: Select all

You must train a positive number of units!
Not sure why...

Re: Error Messages Not Breaking

Posted: Sat Sep 14, 2013 3:27 am
by Epiales
Boy don't I feel stupid :lol: :lol: :lol: :oops: :oops: :oops:

Well, it might help someone down the road. The isset are both put to "train" lmao... So in the forms, just changed them from train to one of them and train1 to the other LOL. YAY me!