I'm new at php, started to make a guessing game, and I wanted the script to tell you how many guesses you made. What did I do wrong/how do I fix it?
Thanks!
PHP Code:
<html>
<head>
<title>Guessing Game</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="numberform" method="post" action="Guessinggame.php">
<p align="center"><font face="Geneva, Arial, Helvetica, sans-serif">PHP Guessing
Game</font></p>
<p align="center"><font face="Geneva, Arial, Helvetica, sans-serif">Guess the
number! The number is between 0 and 10,000!</font></p>
<p> <font face="Geneva, Arial, Helvetica, sans-serif">
<input name="numberguess" type="text" id="numberguess" value="0" maxlength="4">
<input type="submit" name="numberSubmit" value="Submit">
</font></p>
</form>
<font face="Geneva, Arial, Helvetica, sans-serif">
<?php
$i = 0;
$correctanswer = 4572;
if($numberguess == $correctanswer){
echo "You got it!\n";
echo "You guessed ".$i." times\n";
}
if($numberguess > $correctanswer){
echo "Too high. Try again!\n";
$i = $i + 1;
}
if($numberguess < $correctanswer){
echo "Too low. Try again!\n";
$i = $i + 1;
}
?>
</font>
</body>
</html>
Comment