Hi, I'm still on hour 9 of Sam's 24 hours and i've run across another stumping block.
It's a Number Guessing script, and it's got a form at the bottom that calls itself again when user presses "ENTER"
for whatever reason my page just refreshes tothe default as if it's the first time the page has been called.
<?php
// force variables to be picked up from Globals
$guess = $GET['guess'];
$num_tries = $GET['num_tries'];
$num_to_guess=42;
$message="";
$num_tries=(isset($num_tries))?++$num_tries:1;
if (!isset($guess))
{
$message="Welcome to the Guessing Machine!";
}
elseif ($guess<$num_to_guess)
{
$message="$guess is too Small! Try a larger number";
}
elseif ($guess>$num_to_guess)
{
$message="$guess is too Big! Try a smaller number";
}
else // must be equivalent
{
$message="Well Done!";
}
$guess = (int)$guess;
?>
<html>
<head>
<title>Saving State within a hidden field</title>
</head>
<BODY>
<b>
The Number Guessing Script<br><br>
</b>
<?php print $message ?>
<br>
Attempt number: <?php print $num_tries ?>
<form action = "<?php print $PHP_SELF?>" method="POST">
Type your guess in here:
<input type="text" name="guess" value="<?php print $guess ?>">
<input type="hidden" name="num_tries" value="<?php print $num_tries ?>">
</form/>
</body>
</html>
Can anyone tell me what I've done wrong?