Error Messages Not Breaking [Resolved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Error Messages Not Breaking [Resolved]

Post 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...
Last edited by Epiales on Sat Sep 14, 2013 3:28 am, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Error Messages Not Breaking

Post 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!
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”