wasabitakoyaki Posted December 19, 2011 Share Posted December 19, 2011 This is my php code to handle an html form ######################################## <!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>Form Feedback</title> </head> <body> <?php # Script 2.2 -handle_form.php $name = $_REQUEST['name']; $email = $_REQUEST['email']; $comments = $_REQUEST['comments'] echo "<p>Thank you, <b>$name</b>, for the following comments:<br /> <tt>$comments</tt></p> <p>We will reply to you at <i>$email</i>.</p>\n"; ?> </body> </html> ################################# And this is my form that I am trying to handle <!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>Simple HTML Form</title> <style type="text/css" title="text/css" media="all"> label { font-weight: bold; color: #300ACC; } </style> </head> <body> <!-- Script 2.1. - form.html --> <form action="handle_form.php" method="post"> <fieldset><legend>Enter your information in the form below: </legend> <p><label>Name: <input type="text" name="name size="20" maxlength= "40" /></label></p> <p><label>Email Address: <input type="text" name="email" size="40" maxlength="60" /></label></p> <p><label for"gender">Gender: </label><input type="radio" name="gender" value="M" /> Male <input type="radio" name="gender" value="F" /> Female</p> <p><label>Age: <select name="age"> <option value="0-29">Under 30 </option> <option value="30-60">Between 30 and 60</option> <option value="60+">Over 60 </option> </select></label></p> <p><label>Comments: <textarea name="comments" rows="3" cols="40"> </textarea></label></p> </fieldset> <p align="center"><input type= "submit" name="submit" value= "Submit My Information" /></p> </form> </body> </html> ######################### But when I try and submit the form it gives me this error HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. It works with just php code (i.e. the numbers.php) from chapter 1 and with loading the form itself and I have been trying to google to find out what is wrong but I am stumped. Thanks for any help Link to comment Share on other sites More sharing options...
Redscouse Posted December 20, 2011 Share Posted December 20, 2011 just had a quick scan through your post and i notice you have a semi-colon missing at the end of this line: $comments = $_REQUEST['comments'] it should be: $comments = $_REQUEST['comments']; Hope this helps. 1 Link to comment Share on other sites More sharing options...
phpRob Posted December 20, 2011 Share Posted December 20, 2011 I've had a quick look too and also found this error <p><label>Name: <input type="text" name="name size="20" maxlength= "40" /></label></p> You have a html error here and you've missed the closing quotation on 'name', should be: <p><label>Name: <input type="text" name="name" size="20" maxlength= "40" /></label></p> Hope that helps too. 1 Link to comment Share on other sites More sharing options...
wasabitakoyaki Posted December 20, 2011 Author Share Posted December 20, 2011 Thanks so much fixing the semi colon fixed the problem, guess I need to proof read better. Link to comment Share on other sites More sharing options...
Jonathon Posted December 21, 2011 Share Posted December 21, 2011 Or get a good editor with syntax highlighting, then when you miss something like this you can tell as the colours don't match up 1 Link to comment Share on other sites More sharing options...
oddlaw Posted December 21, 2011 Share Posted December 21, 2011 I am also having an issue with this..... both of the forms work w/o error but when i run handle_form.php the variable values are blank. if i run form.html i have all the fields but when i click submit it does nothing. i checked like it says in the book for the proper capitalization of the variables, but my text editor would tell me if the $_REQUEST is wrong or not. every other script has worked up to this point and i'm not sure what is going on. my code for the form.html is as follows: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset-utf-8" /> <title>Simple HTML Form</title> <style type="text/css" title="text/css" media="all"> label { font-weight: bold; color: #300ACC; } </style> </head> <body> <!-- Script 2.1 - form.html --> <form action-"handle_form.php"method="post"> <fieldset><legend>Enter your information in the form below:</legend> <p><label>Name: <input type="text"name="name" size="20" maxlength="40" /></label></p> <p><label>Email Address: <input type="text" name="email" size="40" maxlength="60" /></label></p> <p><label for="gender">Gender:</label><input type="radio" name=gender value="M" /> Male <input type="radio" name="gender"value="F" /> Female</p> <p><label>Age: <select name="age"> <option value="0-29">Under 30</option> <option value="30-60">Between 30 and 60</option> <option value="60+">Over 60</option> </select></label></p> <p><label>Comments: <textarea name="comments" rows="3" cols="40"></textarea></label></p> </fieldset> <p align="center"><input type="submit" name="submit" value="Submit My Information" /></p> </form> </body> </html> my code for the form_handle.php is: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset-utf-8" /> <title>Form Feedback</title> </head> <body> <?php # Script 2.2 - handle_form.php //Create a shorthand for the form data: $name = $_REQUEST['name']; $email = $_REQUEST['email']; $comments = $_REQUEST['comments']; /* Not used: $_REQUEST['age'] $_REQUEST['gender'] $_REQUEST['submit'] */ //Print the submitted information: echo "<p>Thank you, <b>$name</b>, for the following comments:<br /> <tt>$comments</tt></p> <p>We will reply to you at <i>$email</i>.</p>\n"; ?> </body> </html> Link to comment Share on other sites More sharing options...
oddlaw Posted December 21, 2011 Share Posted December 21, 2011 good news and bad news.... good news is i downloaded the code from Larry's WS and put it on my server and the form worked Bad news is that i downloaded the code from Larry's WS and put it on my server and the form worked, lol not sure what the issue is with my code, but obviously something is wrong there. Link to comment Share on other sites More sharing options...
phpRob Posted December 21, 2011 Share Posted December 21, 2011 <form action-"handle_form.php"method="post"> Should be <form action="handle_form.php"method="post"> Lke Jonathon recommended, look for a decent code editor, there are some good ones free for MAC and PC. Text wrangler and notepad++ are to decent ones. Netbeans is a good IDE which is also free. 1 Link to comment Share on other sites More sharing options...
Antonio Conte Posted December 24, 2011 Share Posted December 24, 2011 I would recommend Netbeans or Eclipse. Great IDEs. 1 Link to comment Share on other sites More sharing options...
lutinFou Posted January 11, 2012 Share Posted January 11, 2012 Just been reading your post. Re the text editor, I use Aptana Studio 3 (open source) it is great at spotting my typing errors 1 Link to comment Share on other sites More sharing options...
mjegi Posted September 14, 2012 Share Posted September 14, 2012 Thanks for printing this up. Script 2.1 is not in Larry's download zip file. Link to comment Share on other sites More sharing options...
mjegi Posted September 14, 2012 Share Posted September 14, 2012 Thanks for printing this up. Script 2.1 is not in Larry's download zip file. Well, that's not entirely true. Script 2.1 is not a folder, but form.html is as a standalone file. Apologies to Larry. Link to comment Share on other sites More sharing options...
Recommended Posts