vanyok Posted October 8, 2006 Share Posted October 8, 2006 Hey guys I'm learning PhP and kind stuck with this simple thing ( think it's simple.)Doing a school project. Just a simple "Guessing number" game. Take a look:http://www.shopperstart.com/vanyok/phphome...umber/guess.phpI cannot get "No" button to work at the end of the game prompt "Would you like to play again?"echo "\nWould you like to play again?";echo<<<HERE<form name="playagain" method="get" action="guess.php"><input type="submit" name="yes" value="Yes"><input type="submit" name="no" value="No"></form>HERE;if ($no=="No"){echo "<h3><center>Thanks for playing</center></h3>";}else{}Thats the code behind the button. Seems simply but it's not working, just takes me back to the beginning of the project... Link to comment Share on other sites More sharing options...
Akula_dude Posted October 8, 2006 Share Posted October 8, 2006 not sure, cos i dont have the entire code, but it could be if ($no=="no")instead ofif ($no=="No") Link to comment Share on other sites More sharing options...
pudge Posted October 8, 2006 Share Posted October 8, 2006 BTW, you may want to do something about the source code. Simply by looking at it quickly i noticed that the second input (the hidden one, named guess) has the value of the number you're supposed to guess. I'm no expert on making script hidden, but theres probably a way of containing the value in PHP, and as PHP doesnt show up when you click view source, you wont be able to see what it is Link to comment Share on other sites More sharing options...
vanyok Posted October 8, 2006 Author Share Posted October 8, 2006 BTW, you may want to do something about the source code. Simply by looking at it quickly i noticed that the second input (the hidden one, named guess) has the value of the number you're supposed to guess. I'm no expert on making script hidden, but theres probably a way of containing the value in PHP, and as PHP doesnt show up when you click view source, you wont be able to see what it isYep, I'm aware of that Thats a school project and basically thats one of the things. We're learning how to use hidden forms to pass some values. Everything works great except that prompt at the end.not sure, cos i dont have the entire code, but it could be if ($no=="no")instead ofif ($no=="No")nah, that didnt help.You can see I've used GET method so the address bar says ..php?no=No when pressed but it isn't displaying "THanks for playing"Would you want me to post full program code ? Link to comment Share on other sites More sharing options...
reportingsjr Posted October 8, 2006 Share Posted October 8, 2006 are you just using the $no variable or $no = $_GET['no']; ? You would need to use $_GET to get the value. Link to comment Share on other sites More sharing options...
vanyok Posted October 8, 2006 Author Share Posted October 8, 2006 are you just using the $no variable or $no = $_GET['no']; ? You would need to use $_GET to get the value.ahhh... let me try POST Link to comment Share on other sites More sharing options...
jhecht Posted October 9, 2006 Share Posted October 9, 2006 Or you could just replace $no with $_GET['no']; Link to comment Share on other sites More sharing options...
vanyok Posted October 9, 2006 Author Share Posted October 9, 2006 Cool, that worked, thanks :)Now another quick question. How do I clear the page from everything so it says thanks for playing only ?is there a "Clear Screen" type command in PhP ? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 9, 2006 Share Posted October 9, 2006 A PHP application starts with no output. So, when the script starts, there is nothing there. If you only want to display one thing, then the simple answer is don't display anything before it. As you send output, either through echo or print or HTML outside of the PHP tags, it gets sent to the browser, there is no PHP function to take the output back. The browser displays what you send it, so don't send it anything you don't want to display. Link to comment Share on other sites More sharing options...
vanyok Posted October 9, 2006 Author Share Posted October 9, 2006 Thats teh problem.. After clicking on "No, I dont want to play anymore" it displays " Thanks for playing" but all game fields are still present on the screen. I would like to make it that everything dissapears. Is it not possible ? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 9, 2006 Share Posted October 9, 2006 Nothing 'disappears', it either does or does not get sent. If you don't want it on the page, don't send it. Check for the values at the beginning of the page, not in the middle of it, and depending on what the values are, send the appropriate HTML to the browser. Link to comment Share on other sites More sharing options...
vanyok Posted October 9, 2006 Author Share Posted October 9, 2006 Here, this should help:http://ciswebs.smc.edu/cs85/geddes_james/l...uessingGame.phpThats what I'm trying to achieve... so when you guess the number you stay at the same page but text and submit for dissapear.Thank you Link to comment Share on other sites More sharing options...
justsomeguy Posted October 9, 2006 Share Posted October 9, 2006 I understand what you are trying to do, I don't think you're understanding what I'm telling you to do. This is what I'm talking about, you need to do all of your PHP processing on the top of the page, and then display either the form to play the game, or the message that says thanks for playing. Don't send the form first, and then try to determine if they don't want to play, and then try to 'remove' the form. That's not how PHP works, the solution is not to send it in the first place. <?php...if ($no == "No") $play_game = false;else $play_game = true;...$play_choice = <<<HEREWould you like to play again?<form name="playagain" method="get" action="guess.php"><input type="submit" name="yes" value="Yes"><input type="submit" name="no" value="No"></form>HERE;if ($play_game){ ... echo $play_choice;}else{ echo "<h3><center>Thanks for playing</center></h3>";}?> Link to comment Share on other sites More sharing options...
vanyok Posted October 10, 2006 Author Share Posted October 10, 2006 Thank you sir.. I'm a little too new to PhP so excuse my newbiness Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now