Re: Undefined variable issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jim,

I don't think the code you posted matches the code you are running. This
code does not give any errors, it works fine. There is no $guess variable
in line 27.

- Frank

> Hi everyone,
>  
> I'm new to working with PHP (coming from a ASP/VBScript background) and
> I'm currently reading the book "Teach yourself PHP, mySQL, and Apache
in
> 24 hours".  The following code from the code from the book seems to be
> causing an "undefined variable" error when run.  Would any one be able
> tell me why this is happening?  Many thanks!  Jim
>  
> Notice:  Undefined variable:  guess in numguess.php on line 27
>  
> <?php 
> $num_to_guess = 42;
> $num_tries = ( isset($_POST["num_tries"])) ? $num_tries + 1 : 0;
> //$guess = (isset($_POST["guess"])) ? $_POST["guess"] : 0;
> $message = "";
> if (!isset($_POST["guess"])) {
>             $message = "Welcome to the guessing machine!";
> } elseif ( $_POST["guess"] > $num_to_guess) {
>             $message = "$_POST[guess] is too big! Try a smaller
number";
> } elseif ( $_POST["guess"] < $num_to_guess) {
>             $message = "$_POST[guess] is too small! Try a larger
> number";
> } else {
>             $message = "Well done!";
> }
> ?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
> >
> </head>
> <body>
> <h1><?php print $message ?></h1>
> Guess number: <?php print $num_tries ?>
> <form action="<?php print $_SERVER["PHP_SELF"] ?>" method="post">
> Type your guess here: 
> <input name="guess" type="text" value="<?php print $guess ?>">
> <input name="num_tries" type="hidden" value="<?php print $num_tries
?>">
> </form>
> </body>
> </html>
> 

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux