twilitegxa Posted September 15, 2009 Share Posted September 15, 2009 Can anyone tell why my $display_block variable is not showing up properly when I choose the test1 choice from the select list and press submit? It displays correctly (which is above the footer) when I choose the test2 choice from the select list or when the page is initially loaded. What have I done wrong? Can anyone see? Here is my page: <?php session_start(); include("connect_db.php"); if ((isset($_GET['train'])) && ($_GET['train'] == 'test1')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 2); $update_experience = ($experience + 50); if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; }//end while }//end if elseif ((isset($_GET['train'])) && ($_GET['train'] == 'test2')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 10); $update_experience = ($experience + 100); if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; } if ($energy <= 0) { $display_block .= "You cannot train once your energy is depleted. Please rest."; } $display_block .= "</table>"; } else { $display_block .= "Your character did not train."; } ?> <html> <head> <title>Sailor Moon RPG - Training Board</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Training Board</h1> <?php print $display_block; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/174392-solved-variable-not-displaying-properly/ Share on other sites More sharing options...
mikesta707 Posted September 16, 2009 Share Posted September 16, 2009 whats it displaying Quote Link to comment https://forums.phpfreaks.com/topic/174392-solved-variable-not-displaying-properly/#findComment-919238 Share on other sites More sharing options...
venturemc Posted September 16, 2009 Share Posted September 16, 2009 Not that I'm an expert on PHP or anything, but it appears that perhaps the issue is in your train.php script? It's not posted, so we can't see what's happening. I'd look there to see what is supposed to happen when you select test2. Just a thought.... Quote Link to comment https://forums.phpfreaks.com/topic/174392-solved-variable-not-displaying-properly/#findComment-919245 Share on other sites More sharing options...
twilitegxa Posted September 16, 2009 Author Share Posted September 16, 2009 This is train.php: <?php session_start(); include("connect_db.php"); if ((isset($_GET['train'])) && ($_GET['train'] == 'test1')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 2); $update_experience = ($experience + 50); if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; }//end while }//end if elseif ((isset($_GET['train'])) && ($_GET['train'] == 'test2')) { $display_block = "<h3>Train Your Character To Level Up</h3> <h4>Choose a different <a href=choose_train.php>character</a> to train?</h4> <table cellpadding=3 cellspacing=3> <tr>"; $get_player_info = "select * from training WHERE identity = '$_GET[identity]'"; $get_player_info_res = mysql_query($get_player_info, $conn) or die(mysql_error()); while ($player_info = mysql_fetch_array($get_player_info_res)) { $id = $player_info['id']; $identity = $player_info['identity']; $level = $player_info['level']; $energy = $player_info['energy']; $experience = $player_info['experience']; $update_energy = ($energy - 10); $update_experience = ($experience + 100); if ($energy > 0) { $lose_energy = mysql_query("UPDATE training SET energy ='$update_energy' WHERE identity = '$identity'"); $gain_experience = mysql_query("UPDATE training SET experience ='$update_experience' WHERE identity = '$identity'"); } $display_block .= " <td valign=top> <form action=train.php> <select name=train> <option>test1</option> <option>test2</option> </select> <input type=submit name=submit value=Train> <input type='hidden' name='identity' value='$identity' /> </form> </td> <td valign=top>Player: $identity<br /> Level: $level<br /> Energy: $energy<br> Current Experience: $experience<br /> Experience To Next Level:<br /> </td> </tr>"; } if ($energy <= 0) { $display_block .= "You cannot train once your energy is depleted. Please rest."; } $display_block .= "</table>"; } else { $display_block .= "Your character did not train."; } ?> <html> <head> <title>Sailor Moon RPG - Training Board</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Training Board</h1> <?php print $display_block; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html> Here is what's supposed to look like: And what is does look like: Quote Link to comment https://forums.phpfreaks.com/topic/174392-solved-variable-not-displaying-properly/#findComment-919247 Share on other sites More sharing options...
twilitegxa Posted September 16, 2009 Author Share Posted September 16, 2009 I guess I figured it out. I moved the closing table tag to the very end of the php code and it's fine. Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/174392-solved-variable-not-displaying-properly/#findComment-919255 Share on other sites More sharing options...
venturemc Posted September 16, 2009 Share Posted September 16, 2009 I can't see any issues (the if and elseif clauses appear to be identical - I assume that's just for testing?) I'd try playing with the structure a bit. A quick swap of test1 and test2 might give you a clue (add something unique to one of the clauses for test purposes): if ((isset($_GET['train'])) && ($_GET['train'] == 'test2')) { .... } elseif ((isset($_GET['train'])) && ($_GET['train'] == 'test1')) { ..... ? you could also try a differnt structure like a switch: if (isset($_GET['train']){ switch ($GET_['train']){ case 'test1: case 'test2: default: } else{ fail } or nested if statements if (isset($_GET['train']){ if ($_GET['train'] == 'test1'){ } else{ //test2 } } else{ fail } I'm not saying there's anything wrong with your structure, but it might be easier to trace one condition at a time with a more obvious structure. Quote Link to comment https://forums.phpfreaks.com/topic/174392-solved-variable-not-displaying-properly/#findComment-919263 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.