Undefined index and constant question
Posted: Tue Apr 13, 2010 11:31 pm
I recently started to learn PHP and a lot of this is starting to make sense, once in a while I get stump and confused at why some things just don’t work the way the book I am following works out.
This week I started to learn about forms and how to use different methods of building them out.
This example is from my book and even though the actions and results are what the book says they should, I get an error message that I just can’t figure it out how to fix it.
I am using PHP 5.3.0 / apache 2.2.11 / mysql 5.1.36 on my test server
When I open the form with my browser (IE, Mozilla, and Chrome) it get this error message followed by the form.
When I enter a value to convert it into meters [34 feet into meters] it gives me the correct number but I also get this error message:
I checked the code, double checked all the spelling and I just don’t know what else to check! I tried using “error_reporting(0);” to suppress the error message and it works but still would like to know what the error is about and how to correct it.
Thanks for your help,
This week I started to learn about forms and how to use different methods of building them out.
This example is from my book and even though the actions and results are what the book says they should, I get an error message that I just can’t figure it out how to fix it.
I am using PHP 5.3.0 / apache 2.2.11 / mysql 5.1.36 on my test server
Code: Select all
<html>
<head>
<title>Feet to Meters Comversion Tool</title>
</head>
<body>
<?php
//check to see if the form has been submitted
$feet = $_GET["feet"];
if ($_GET[feet] != NULL) {
echo "<strong>$feet </strong> feet converts to <strong>";
echo $feet * 0.3048;
echo "</strong> meters.<br />";
}
?>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="GET">
<label>Feet:
<input type="text" name="feet" value="<?php echo $feet; ?>" />
</label>
<input type="submit" value="Convert!" />
</form>
</body>
</html>
Code: Select all
Notice: Undefined index: feet in C:\localhost\10-8.php on line 8
Notice: Use of undefined constant feet - assumed 'feet' in C:\localhost\10-8.php on line 9
Notice: Undefined index: feet in C:\localhost\10-8.php on line 9
[[b]the form goes here and it displays correctly[/b]]
When I enter a value to convert it into meters [34 feet into meters] it gives me the correct number but I also get this error message:
Code: Select all
Notice: Use of undefined constant feet - assumed 'feet' in C:\localhost\10-8.php on line 9
34 feet converts to 10.3632 meters.
Thanks for your help,