Jump to content

Would appreciate some help


vanyok

Recommended Posts

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

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

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
Yep, 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

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...