Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question: The php website generates the random number from 1 to 100 when accessi

ID: 3665994 • Letter: Q

Question

Question: The php website generates the random number from 1 to 100 when accessing the first page. And the user will guess the number. The first page contains a text box for accepting a number from the user, and a submit button. The second page will be returned to the user if the guess number is too high or too low. And the page shows a message telling the user "Too High" or "Too Low". The page also contains a text box for accepting a number from the user, and a submit button The third page is returned to the user if the guess is correct. The page displays "Correct", the random number, and the count of tries.

Explanation / Answer

Here is the code as per your requirements.

</head>
<body>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
// define variables and set to empty values
$num = "0";
$x = (rand(10,100)); // generate random number
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$num = test_input($_POST["number"]);
}
function test_input($data)
{
$data = trim($data);
return $data;
}
?>
<h2>PHP Random Number Validation Example</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["nextform.html"]);?>">
Number: <input type="text" name="number">
</form>
<?php
echo "<h2>Your Entered:</h2>";
echo $num;
if($x == $num)
echo "Your guess is correct.";
else
echo "your guess is not correct";
?>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote