View Single Post
  #4 (permalink)  
Old February 18th, 2004, 12:45 PM
richard.york's Avatar
richard.york richard.york is offline
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Well David is correct in pointing out that this is a problem with the register_globals setting, however, Sami, $HTTP_POST_VARS, is deprecated and should never be the recommended method, $_POST should be used instead. In fact the old $HTTP_*_VARS may not even exist in PHP 5... so to keep your script working with the latest version of PHP, use the short superglobal counterparts.

All this and more is mentioned at this URL:
http://www.php.net/manual/en/languag...predefined.php

If register_globals is turned off then the global $Choice will not be defined, and as such under error_reporting E_ALL will throw a notice level error, in this case a variable that is used before being defined. So it clearly indicates a problem, since Knight clearly needs a varible defined from his form. Predefined variables to the rescue!

Use...
echo $_POST['Choice'];

Or better yet...
If choice exists and it isn't empty, output it.. otherwise throw an error.

if (isset($_POST['Choice']) && !empty($_POST['Choice']))
{
    echo $_POST['Choice'];
}
else
{
    echo 'Error: you did not indicate the eating of haggis!';
}

isset and empty are basic language constructs (not functions), isset returns a boolean value based on whether the variable passed to it exists or not. empty returns a boolean value based on whether the vairable passed to it contains an 'empty' value if true the variable contains one of 0, '0', null, false, 'false'.

See:
http://www.php.net/isset
http://www.php.net/empty

Loads of information on this very frequently asked question:
http://www.google.com/search?q=regis...e:p2p.wrox.com

Regards, ; )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
Reply With Quote