This question already has an answer here:
before the first time that i clicking on "submit" the source looking like this (fine) :
<html>
<body>
Guess a number between 1 and 100
<form action="/www/lesson4/gueeANumber.php" method="GET">
<input type="text" name="my_answer" autofocus>
<input type="hidden" name="number" value="61">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
after the first submit :
Too Low<br>
<html>
<body>
Guess a number between 1 and 100
<form action="/www/lesson4/gueeANumber.php" method="GET">
<input type="text" name="my_answer" autofocus>
<input type="hidden" name="number" value="<br />
<b>Notice</b>: Undefined variable: number in <b>C:\xampp\htdocs\www\lesson4\gueeANumber.php</b> on line <b>30</b><br />
">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
and here's my entire code with the php :
<?php
if(!empty($_GET))
{
if(isset($_GET['number'])){
$guess=(int)$_GET['my_answer'];
$num=(int)$_GET['number'];
if($guess<$num){
echo "Too Low"."<br>";
}
else if($guess>$num){
echo "Too High"."<br>";
}
else{
echo "Correct!";
exit();
}
}
}
else
{
$number=mt_rand(1,100);
}
?>
<html>
<body>
Guess a number between 1 and 100
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="GET">
<input type="text" name="my_answer" autofocus>
<input type="hidden" name="number" value="<?php echo $number?>">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
the idea is that the user should guess a number between 1 and 100 and the code should tell him if its lower or higher, and all the time refresh the page, if he correct so we should exit.
Aucun commentaire:
Enregistrer un commentaire