Forum Moderators: coopster
MyForm.html
<html>
<head>
<title>my form</title>
</head>
<body>
<form action=process.php METHOD=post>
<input type=checkbox name=mychoice value="210">
<input type=submit value=Confirm>
</form>
</body>
</html>
process.php
<html>
<head>
<title>process form</title>
</head>
<body>
<?php echo ($mychoice);?>
</body>
</html>
So I go to IIS, select MyForm.html, and browse it. It opens up in Internet Explorer. I tick the box and click SUBMIT. The PHP page opens and gives an error "Notice: Undefined variable" for the form checkbox "mychoice".
How can I fix this?
Thanks,
May
you will need to access the variable through the $_POST array
so
<?php echo $_POST['mychoice'];?>
though a bit of shorthand for you. This means the same thing
<?= $_POST['mychoice']?>
if you jst want to echo the value of a var
have a look here for $_POST among others
PHP Predefined variables [ca.php.net]
But I've found endless "Undefined Variable" and "Undefined Index" errors in ready-to-use code I've downloaded from reputable sites. Of 10 different guestbook files, not one has worked without giving an "Undefined Variable" error.
Is there something that should be configured after installing PHP on IIS? Surely all this code can't be problematic?
Thx!
May
Perhaps the most controversial change in PHP is when the default value for the PHP directive register_globals went from ON to OFF in PHP 4.2.0. Reliance on this directive was quite common and many people didn't even know it existed and assumed it's just how PHP works. This page will explain how one can write insecure code with this directive but keep in mind that the directive itself isn't insecure but rather it's the misuse of it.
so anything developped before version 4.2.0 may use old settings.
Take a look at using extract [ca3.php.net] as a quick fix for older scripts.