title: Random number generator game in PHP using a form
body: <p>I am trying to create a webpage that prompts the user to guess a number from 1 to 5 which is randomly generated and stored in the form. </p>
  
  <p>Then, when the form is submitted, the guess is checked against the random number and if the guess is incorrect, the user is prompted to guess again but the random value stays the same with each guess. </p>
  
  <p>My issue is that once the user submits the form, the random number is not showing up when the user is prompted to try again.</p>
  
  <pre><code>else if (isset($_POST["firstname"])) {
      echo $_POST['firstname'] . $_POST['lastname'];
      echo "Hi " . $_POST['firstname'] . " " . $_POST['lastname'] . "!";
      ?&gt;
      &lt;html&gt;
          &lt;form name="number" action="random.php" method="post"&gt;
              &lt;p&gt;Enter a guess: &lt;input type="text" name="guess" /&gt;&lt;/p&gt;
              &lt;input type="hidden" name="numtobeguessed" value="&lt;?php echo $_POST["numtobeguessed"]; ?&gt;" &gt;&lt;/p&gt;
              &lt;input type="submit" value="Guess!" /&gt;
          &lt;/form&gt;
      &lt;/html&gt;
      &lt;?php
      $_POST["numtobeguessed"] = rand(1, 5);
      $guessed = $_POST["numtobeguessed"];
      echo "Number to be guessed " . $guessed;
  
  } else if (isset($_POST["guess"])) {
      if ($_POST["guess"] != $_POST["guessed"]) {
          echo $_POST["guess"] . " is not correct";
          ?&gt;
          &lt;form name="number1" action="random.php" method="post"&gt;
              &lt;p&gt;Enter a guess: &lt;input type="text" name="guess" /&gt;&lt;/p&gt;
              &lt;input type="hidden" name="numtobeguessed" value="&lt;?php echo $_POST["guessed"]; ?&gt;" &gt;&lt;/p&gt;
              &lt;input type="submit" value="Guess!" /&gt;
              &lt;?php
          }
      }
      ?&gt;
  </code></pre>