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
This is my html code:
Expand|Select|Wrap|Line Numbers
- <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>
When I open the form with my browser (IE, Mozilla, and Chrome) it get this error message:
Notice: Undefined index: feet in /localhost/example2.php on line 10
After entering a value to calculate, the form process the input and presents me the correct product. The form does what it is supposed to do and there is no problems I can see with the functionality of it. I just would like to know what the error is about and how to correct it.
Thanks for your help,