Jump to content

php high-low game number of tries


DimitriosZ

Recommended Posts

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"]); ?>

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.