Candice Posted March 19, 2011 Share Posted March 19, 2011 I've been working on building the feedback form as detailed in chapter 3. However, upon submitting the feedback form, the user's name does not appear. For example, in the handle_form.php, it comes up: "Thank you, Ms. , for your comments. You stated that you found this example to be 'excellent' and added: Great job!" The person's name is missing. I have copied my code below. Can you let me know if I'm overlooking something and why it doesn't include the person's name? --------Here is the HTML---------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang"en" <head> <meta http-equiv="content-type" content'"text/html; charset=utf-8" /> <title>Feedback Form</title> </head> <body> <!--Script 3.1 - feedback.html--> <div><p>Please Complete this form to submit your feedback:</p> <form action="handle_form.php" method="post"> <p>Name: <select name="title"> <option value="Mr.">Mr.</option> <option value="Mrs.">Mrs.</option> <option value="Ms.">Ms.</option> </select> <input type="text" name="email" size="20" /></p> <p>Response: This is... <input type="radio" name="response" value="excellent" />excellent <input type="radio" name="response" value="okay" />okay <input type="radio" name="response" value="boring" />boring <p>Comments: <textarea name="comments" rows="3" cols="30"></textarea></p> <input type="submit" name="submit" value="Send my feedback" /> </form> </div> </body> </html> ----------------------Here is the PHP---------------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang"en" <head> <meta http-equiv="content-type" content'"text/html; charset=utf-8" /> <title>Your Feedback</title> </head> <body> <?php $title = $_POST['title']; $name = $_POST['name']; $response = $_POST['response']; $comments = $_POST['comments'] print"<p>Thank you, $title; $name, for your comments.</p> <p>You stated that you found this example to be '$response' and added: <br />$comments</p>"; ?> </body> </html> Link to comment Share on other sites More sharing options...
Stuart Posted March 19, 2011 Share Posted March 19, 2011 To see the problem place print_r($_POST) at the top of your PHP script and look at the output - you'll see that $_POST['name'] doesn't exist - you need to change your HTML form names. Hope that helps 1 Link to comment Share on other sites More sharing options...
Candice Posted March 19, 2011 Author Share Posted March 19, 2011 Thanks for your reply! Though, I'm still a bit confused. Are you meaning here: "</select> <input type="text" name="email" size="20" /></p>" in my html doc? I changed it to: </select> <input type="text" name="name" size="20" /></p> But it still is not working. Link to comment Share on other sites More sharing options...
Stuart Posted March 19, 2011 Share Posted March 19, 2011 Thats the only problem I can see with your code - when you fixed it did you just press refresh in the browser? If so then you're just resubmitting the old POST data which will contain $_POST['email'] rather then the new $_POST['name']. Access the page fresh i.e. type the URL in again and hit enter. Then resubmit the details and it should work... unless I'm missing something. 1 Link to comment Share on other sites More sharing options...
Candice Posted March 20, 2011 Author Share Posted March 20, 2011 Ah! Yes, that was it! I feel silly now! Works great! Thanks. Thats the only problem I can see with your code - when you fixed it did you just press refresh in the browser? If so then you're just resubmitting the old POST data which will contain $_POST['email'] rather then the new $_POST['name']. Access the page fresh i.e. type the URL in again and hit enter. Then resubmit the details and it should work... unless I'm missing something. Link to comment Share on other sites More sharing options...
Recommended Posts