DimitriosZ Posted April 28, 2021 Share Posted April 28, 2021 I have just did this php code for the high-low game but the $tries variable always goes down to 0 when I refresh..Can someone help me to return the $tries to browser with the url? Thank you <html> <?php $tries = 0 ?> <body> <form action="http://195.251.218.44/code/workspace/fin19178/2021/ergasia2/askisi2.php" method="post"> Make a guess: <input type="number" name="number" id="number" required> <input type="submit" value="Guess"> </form> </body> </html> <?php function High_Low($guess){ $tries += 1; $hidden_number= 74; if ($guess < $hidden_number) { return "Give me a higher number!"; } elseif ($guess > $hidden_number) { return "Give me a lower number!"; } else { return "Congratulations,You have found it in:" . $tries . " tries!"; } } ?> <?php echo High_Low($_POST["number"]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/312559-php-high-low-game-number-of-tries/ Share on other sites More sharing options...
gw1500se Posted April 28, 2021 Share Posted April 28, 2021 First please use the code icon (<>) in the menu for your code and select PHP. As to your problem, keep in mind that PHP is stateless and server side. It does not know anything about a previous display of a page. To accomplish what you want you need to use sessions. Quote Link to comment https://forums.phpfreaks.com/topic/312559-php-high-low-game-number-of-tries/#findComment-1586216 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.