I'm trying the examples on Kevin Yank's "Build Your Own Database Driven Web Site Using PHP & MySQL".
In chapter 3, he talks about $_GET and $_POST. So far, everything has been fine with $_GET. However, I'm having issues with $_POST. I've written the code exactly as he did, but I get this error on the site:
Notice: Undefined index: firstname in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Test\welcome1.php on line 9
Notice: Undefined index: lastname in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Test\welcome1.php on line 10
However, on IE, I get no error.
Here is the code:
welcome5.html file...
Code HTML4Strict:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Welcome5</title> </head> <body> <form action="welcome5.php" method="post"> <div><label for="firstname">First name: <input type="text" name="firstname" id="firstname"/></label></div> <div><label for="lastname">Last name: <input type="text" name="lastname" id="lastname"/></label></div> <div><input type="submit" value="GO"/></div> </form> </body> </html>
welcome5.php file...
Code PHP:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Welcome5</title> </head> <body> <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; echo "Welcome to our website, " . htmlspecialchars($firstname, ENT_QUOTES, "UTF-8") . " " . htmlspecialchars($lastname, ENT_QUOTES, "UTF-8") . "!"; ?> </body> </html>


Reply With Quote




Bookmarks