Sorry; is this a PHP5 question or a PHP4.3 question?
PHP Code:
if (!isset($_POST['guess']))
{
$message = "Welcome to the guessing machine!";
}
else if ($_POST['guess'] > $num_to_guess)
{
$message = $_POST['guess'] . " is to big! Try a smaller number";
}
else if ($_POST['guess'] < $num_to_guess)
{
$message = $_POST['guess'] . " is too small! Try a larger number";
}
else
{ // must be equivalent
$message = "Well done! " . $_POST['guess'] . " is correct";
}
$guess = $_POST['guess'];
If $_POST['guess'] is not set (i.e., that field was empty); then the message will be set to "Welcome to the guessing machine!".
The problem is, even if it
wasn't set, the code still tries to use it later on (the line $guess=$_POST['guess']; ). That's when the error will happen. Considering that $guess is used later to repopulate the form field, a reasonable fix would be to add a line immediately after the "Welcome to the guessing machine!" line to make sure $_POST['guess'] is set with an empty value:
PHP Code:
$_POST['guess']="";