mercredi 24 février 2016

Random Number Resets

My random number generates on page load, but seems to reset when the user clicks the "Guess" button. I'm not sure what I'm doing wrong and just starting this program. If you answer, please also explain, as I'm trying to learn what I'm doing. Thank you!

<!doctype html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>PHP Homework 2</title>
        <link rel="stylesheet" href="styles/styles.css">
    </head>

    <body>
        <section id="main">
            <h1>Play the Guessing Game!</h1>
            <section id="left">
                <h2>Take a Guess!</h2>
                <form action="mine.php" method="post">
                    <div id="guessBox">
                        <label id="guessLB">Your Guess:</label>
                        <input id="guessTB" class="num" type="number" name="guessTB" max="1000" min="1">
                        </input>
                    </div>
                    <input type="submit" id="guessButton" name="guessBTN" value="Guess" />
                </form>
            </section>
            <section id="right">
                <h2>Game Stats</h2>
                <?php 

                    if(isset($_POST['guessTB'])) 
                    {
                        $randomNum = $_POST['guessTB'];
                    } 
                    else 
                    {
                        $randomNum = rand(1,100);
                    }                       

                    echo "<p>Random Number: $randomNum</p>";
                ?>      
            </section>
        </section>          
    </body>
</html>




Aucun commentaire:

Enregistrer un commentaire