Jump to content
Larry Ullman's Book Forums

Problem With Chapter 2 Handling Php Form


Recommended Posts

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

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.

  • Upvote 1
Link to comment
Share on other sites

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

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

<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.

  • Upvote 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 8 months later...
 Share

×
×
  • Create New...