I'm trying to figure out why my reset "Restart" button is not working properly because the incremented guessses and still going up. I also need to add a button that displays the correct number if someone gives up. Thanks for the help earlier guys with the warning, these are the two parts I am stuck on.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Guessing Game</title>
</head>
<body>
<center><form action="game.php" method="POST">
Guess a number 1-100:<input type="text" name="userGuess"/>
<input type="submit" value="Guess"/>
<center><form action="game.php">
<input type="reset" value="Restart"/>
</form></center>
</body>
</html>
<?php
session_start();
$_SESSION['randNum'] = isset($_SESSION['randNum']) ? $_SESSION['randNum'] : rand(0, 100);
$_SESSION['guesses'] = isset($_SESSION['guesses']) ? $_SESSION['guesses'] : 0;
$randNum = $_SESSION['randNum'];
$userGuess = $_POST['userGuess'];
$userGuess = filter_input(INPUT_POST, "userGuess");
if (isset($randNum)) {
if ($userGuess<$randNum) {
echo "<center>You guessed too low!</center>";
$_SESSION['guesses']++;
echo $_SESSION['guesses'];
}
if ($userGuess>$randNum) {
echo "<center>You guessed too high!</center>";
$_SESSION['guesses']++;
echo $_SESSION['guesses'];
}
if ($userGuess==$randNum) {
echo "<center>Congratulations You're right!!!</center>";
unset($_SESSION["randNum"], $_SESSION['guesses']);
}
if ($userGuess>100 || $userGuess<0) {
echo "<center>Please enter a number betweeen 1 and 100!</center>";
}
}
else {
echo "Please enter a number between 1 and 100";
}
?>