seany123 Posted April 23, 2009 Share Posted April 23, 2009 basically i have a code which _POSTS values and to stop more than 1 value being used at once i have had to use exit; problem with using exit; is that it wont show any of the tables or html or <div> below it. <?php include("lib.php"); define("PAGENAME", "Gym"); $player = check_user($secret_key, $db); include("templates/private_header3.php"); ?> <html> <head> <title>MafiaKiller</title> <link rel="stylesheet" href="http://mafiakiller.co.cc/css/style.css" type="text/css" media="all" /> </head> <body alink="#cc9900" vlink="#cc9900" link="#cc9900"> </div> </div> <div id="left_c"><div class="g_content"><h3> Gym</h3><div class="g_text"> <table width='100%'> <tr> <?php $energyreduce = ($player->energy); //UPDATE STRENGTH. if ($_POST['full_strength']) { if($player->energy < 1) { echo"<br>You dont have any energy left"; exit; } $query = $db->execute("update `players` set `energy`=?, `awake`=?, `strength`=?, `total`=? where `id`=?", array($player->energy - $player->energy, $player->awake - $awakeloss, $player->strength + $statgain, $player->total + $statgain, $player->id )); if ($statgain >= 1){ echo "<br>You gained " . number_format($statgain, 2, ".", ",") . " Strength"; exit; } } ?> <?php $energyreduce = ($player->energy); //UPDATE DEFENSE. if ($_POST['full_defense']) { if($player->energy < 1) { echo"<br>You dont have any energy left"; exit; } $query = $db->execute("update `players` set `energy`=?, `awake`=?, `defense`=?, `total`=? where `id`=?", array($player->energy - $player->energy, $player->awake - $awakeloss, $player->defense + $statgain, $player->total + $statgain, $player->id )); if ($statgain >= 1){ echo "<br>You gained " . number_format($statgain, 2, ".", ",") . " Defense"; exit; } } ?> <?php $energyreduce = ($player['energy']); // UPDATE SPEED. if ($_POST['full_speed']) { if($player->energy < 1) { echo"<br>You dont have any energy left"; exit; } $query = $db->execute("update `players` set `energy`=?, `awake`=?, `speed`=?, `total`=? where `id`=?", array($player->energy - $player->energy, $player->awake - $awakeloss, $player->speed + $statgain, $player->total + $statgain, $player->id )); if ($statgain >= 1){ echo "<br>You gained " . number_format($statgain, 2, ".", ",") . " Speed"; exit; } } ?> <? if ($_POST['energy_str'] + $_POST['energy_def'] + $_POST['energy_spd'] > $player->energy) { echo"you dont have enough energy left"; exit; } else if ($_POST['energy_str']) { if($player->energy < 1 || $_POST['energy_str'] > $player->energy) { echo "<br>You dont have any energy left"; exit; } $query = $db->execute("update `players` set `energy`=?, `awake`=?, `strength`=?, `total`=? where `id`=?", array($player->energy - $_POST['energy_str'], $player->awake - $awakeloss2, $player->strength + $statgain2, $player->total + $statgain2, $player->id )); echo "<br>You trained\n" . $_POST['energy_str'] . "\ntimes and You gained " . number_format($statgain2, 2, ".", ",") . " Strength<br>" ; } ?> <? if ($_POST['energy_str'] + $_POST['energy_def'] + $_POST['energy_spd'] > $player->energy) { echo"you dont have enough energy left"; exit; } else if ($_POST['energy_def']) { if($player->energy < 1 || $_POST['energy_def'] > $player->energy) { echo "<br>You dont have any energy left"; exit; } $query = $db->execute("update `players` set `energy`=?, `awake`=?, `strength`=?, `total`=? where `id`=?", array($player->energy - $_POST['energy_def'], $player->awake - $awakeloss3, $player->defense + $statgain3, $player->total + $statgain3, $player->id )); echo "<br>You trained\n" . $_POST['energy_def'] . "\ntimes and You gained " . number_format($statgain3, 2, ".", ",") . " Defense<br>" ; } ?> <? if ($_POST['energy_str'] + $_POST['energy_def'] + $_POST['energy_spd'] > $player->energy) { echo"you dont have enough energy left"; exit; } else if ($_POST['energy_spd']) { if($player->energy < 1 || $_POST['energy_spd'] > $player->energy) { echo "<br>You dont have any energy left"; exit; } $query = $db->execute("update `players` set `energy`=?, `awake`=?, `strength`=?, `total`=? where `id`=?", array($player->energy - $_POST['energy_spd'], $player->awake - $awakeloss4, $player->defense + $statgain4, $player->total + $statgain4, $player->id )); echo "<br>You trained\n" . $_POST['energy_spd'] . "\ntimes and You gained " . number_format($statgain4, 2, ".", ",") . " Speed<br>" ; } ?> <form method='post'><br> <table width='80%' align='center'> <tr> <td width='10'> </td> <td width='100'> </td> <td align='center'> </td> <td align='center'><img src="bargen.php?energy" alt="energy"></td> <td align='center'> </td> <td width='10'> </td> <td width='100'> </td> </tr> <tr> <td rowspan='3' width='10'> </td> <td rowspan='3' width='100'> </td> <td align='center'><b>Strength</b></td> <td align='center'><b>Defense</b></td> <td align='center'><b>Speed</b></td> <td rowspan='3' width='10'> </td> <td rowspan='3' width='100'> <b>Refill:</b><br><br> <a href='refillenergy2.php'> Energy</a><br><br> <a href='refillawake2.php'> Awake</a><br> </td> </tr> <tr> <td align='center'><input type='text' name='energy_str' value='0' size='5' maxlength='5'></td> <td align='center'><input type='text' name='energy_def' value='0' size='5' maxlength='5'></td> <td align='center'><input type='text' name='energy_spd' value='0' size='5' maxlength='5'></td> </tr> <tr> <td align='center'><input type='submit' name='full_strength' value='All Strength'></td> <td align='center'><input type='submit' name='full_defense' value='All Defense'></td> <td align='center'><input type='submit' name='full_speed' value='All Speed'></td> </tr> <tr> <td colspan='7' align='center'><input type='submit' name='train' value='Train'></td> </tr> </table> </form> </tr> </table></div></div> <div class="g_content"><h3> Attributes</h3><div class="g_text"> <table width='100%'> <tr> <td width='15%'>Strength:</td> <td width='35%'><?= $english_format_number = number_format($player->strength);?></td> <td width='15%'>Defense:</td> <td width='35%'><?= $english_format_number = number_format($player->defense);?></td> </tr> <tr> <td width='15%'>Speed:</td> <td width='35%'><?= $english_format_number = number_format($player->speed);?></td> <td width='15%'>Total:</td> <td width='35%'><?= $english_format_number = number_format($player->total);?></td> </tr> </table></div></div> i need a way for it to not run the other queries but still do the <div>s and stuff Quote Link to comment https://forums.phpfreaks.com/topic/155278-how-to-do-this-without-exit/ Share on other sites More sharing options...
Maq Posted April 23, 2009 Share Posted April 23, 2009 Use an else so the query only gets executed if the statement isn't true, rather than just stopping the entire script. Instead of using "exit;" you could alternatively use "break;". Quote Link to comment https://forums.phpfreaks.com/topic/155278-how-to-do-this-without-exit/#findComment-816957 Share on other sites More sharing options...
seany123 Posted April 23, 2009 Author Share Posted April 23, 2009 i just tried break; it didnt change anything. what change some ifs to else if? or ??? Quote Link to comment https://forums.phpfreaks.com/topic/155278-how-to-do-this-without-exit/#findComment-816961 Share on other sites More sharing options...
Maq Posted April 23, 2009 Share Posted April 23, 2009 i just tried break; it didnt change anything. what change some ifs to else if? or ??? Sorry, break; was for future reference, it will break out of a loop rather than exit the whole script. I meant use else. If the the IF statement are not true, then execute the query. If I'm understanding your problem correctly then this should work: if($player->energy { echo" You dont have any energy left"; exit; } else { $query = $db->execute("update `players` set `energy`=?, `awake`=?, `strength`=?, `total`=? where `id`=?", array($player->energy - $player->energy, $player->awake - $awakeloss, $player->strength + $statgain, $player->total + $statgain, $player->id )); } Quote Link to comment https://forums.phpfreaks.com/topic/155278-how-to-do-this-without-exit/#findComment-816976 Share on other sites More sharing options...
seany123 Posted April 23, 2009 Author Share Posted April 23, 2009 no the actual queries and _POSTS work fine... its just when it echos "You dont have any energy left" or whatever.. it stops displaying the forms and tables etc Quote Link to comment https://forums.phpfreaks.com/topic/155278-how-to-do-this-without-exit/#findComment-817606 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.