jsparrow Posted January 11, 2011 Share Posted January 11, 2011 I have been going back over this and can not locate the problem. I really need someone else's fresh eyes to look at this for me. I am trying to have an html page send info to a php page using POST. I keep getting the error Undefined index *** on line **. I have done this before, but can not locate the problem. Here is the html code for the input page: <!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>Pre-Registration</title> <link rel="stylesheet" type="text/css" href="preregistration.css"/> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <h1>Pre-Registration</h1> <h3> Please fill out the below pre-registration form. </h3> <form method="post" action="reg5.php" enctype="text/plain" onReset="return setDisabled()"> <table> <tr> <td class="name">First Name <input class="name" type="text" name="firstname"/> </td> <td class="name">Last Name <input class="name" type="text" name="lastname"/> </td> </tr> </table> <br/> <input type="submit" value="Submit" /> <input type="button" value="Reset Form" onClick="this.form.reset()" /> </form> </body> </html> And here is php code that should output: Welcome to our site, firstname lastname <!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>Welcome Page Test</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <p> <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; echo 'Welcome to our site, ' . htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') . htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8'); ?> </p> </body> </html> Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted January 11, 2011 Share Posted January 11, 2011 typically, that means you are referencing an index that doesn't exist. without seeing the parts of the error you omitted, i can't say for sure, but i suspect it's caused by referencing those $_POST variables. you should check to see if they are set before using them. one way: if (isset($_POST['firstname'])) { $firstname = $_POST['firstname']; } if (isset($_POST['lastname'])) { $lastname = $_POST['lastname']; } Quote Link to comment Share on other sites More sharing options...
jsparrow Posted January 11, 2011 Author Share Posted January 11, 2011 The error and text I am getting is: Notice: Undefined index: firstname in C:\Apache2.2\htdocs\formtest\reg5.php on line 12 Notice: Undefined index: lastname in C:\Apache2.2\htdocs\formtest\reg5.php on line 13 Welcome to our site, I'm really confused since I have another page that is almost similar to this and it works fine. Is the problem on the html page with some code issue and it not passing the firstname & lastname - or - is it a problem on the php code side not interpreting what was sent correctly? Thx. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 11, 2011 Share Posted January 11, 2011 Is the second code chunk you posted arrived at as a direct result of submitting the form in the first code chunk, or does something else happen between the two? Quote Link to comment Share on other sites More sharing options...
jsparrow Posted January 12, 2011 Author Share Posted January 12, 2011 The notices of the unassigned page comes up directly from hitting the submit button on the form requesting firstname and lastname. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 12, 2011 Share Posted January 12, 2011 Remove this: enctype="text/plain" Quote Link to comment Share on other sites More sharing options...
jsparrow Posted January 12, 2011 Author Share Posted January 12, 2011 That fixed it. Thx much. Was going cross eyed trying to figure that out. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.