Jump to content
Larry Ullman's Book Forums

Recommended Posts

Sorry I know this is a super simple script but I just can't see the error. I get Server Error HTTP Error 500. I have tried removing bits, tweaking, re-writing and I cannot believe this won't work. It is not my server as I have several hundred php scripts running on it without issue...

 

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> Simple HTML Form</title>

<style type="text/css" title="text/css" media="all">

 

label {font weight: bold; color:#300ACC;}

</style>

</head>

<body>

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

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

 

 

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> Feedback Form</title>

</head>

<body>

 

<?php

$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

Try changing $_REQUEST['comments'] to $_REQUEST['Comments'] (uppercase C), and see what happens.

Not sure if that's the issue, but in general, it's probably best to check that you get the right values (or values at all) before using them.

 

  • Upvote 1
Link to comment
Share on other sites

What kind of server are you running this on? Are you running this live or on your localhost. Here is some info on the error:

 

HTTP Error 500 Internal server error

Introduction

The Web server (running the Web Site) encountered an unexpected condition that prevented it from fulfilling the request by the client (e.g. your Web browser or our CheckUpDown robot) for access to the requested URL.

This is a 'catch-all' error generated by the Web server. Basically something has gone wrong, but the server can not be more specific about the error condition in its response to the client. In addition to the 500 error notified back to the client, the Web server should generate some kind of internal error log which gives more details of what went wrong. It is up to the operators of the Web server site to locate and analyse these logs.

500 errors in the HTTP cycle

Any client (e.g. your Web browser or our CheckUpDown robot) goes through the following cycle when it communicates with the Web server:
  • Obtain an IP address from the IP name of the site (the site URL without the leading 'http://'). This lookup (conversion of IP name to IP address) is provided by domain name servers (DNSs).
  • Open an IP socket connection to that IP address.
  • Write an HTTP data stream through that socket.
  • Receive an HTTP data stream back from the Web server in response. This data stream contains status codes whose values are determined by the HTTP protocol. Parse this data stream for status codes and other useful information.

This error occurs in the final step above when the client receives an HTTP status code that it recognises as '500'. (Last updated: March 2012).

 

Fixing 500 errors - general

This error can only be resolved by fixes to the Web server software. It is not a client-side problem. It is up to the operators of the Web server site to locate and analyse the logs which should give further information about the error.
Link to comment
Share on other sites

Okay i found another error, other than changing Comments to comments for the text area name, you have a double quote missing from the handle_form.php echo statement. Correct code for handle_form.php is:

 

<!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>
<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$comments = $_REQUEST['comments'];
/* Not Used:
$_REQUEST['age']
$_REQUEST['gender']
$_REQUEST['submit']
*/
//Print the submitted information:
[b][color=#008000]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";[/color][/b]
?>
</body>
</html>

Link to comment
Share on other sites

Hi milo99, you might find it helpful to use a text editor which provides colour coding - you would have found this error in a second. I've heard good things about Netbeans and TextMate which I'm thinking of trying. I use TextWrangler - its free :)

Link to comment
Share on other sites

Hi milo99, you might find it helpful to use a text editor which provides colour coding - you would have found this error in a second. I've heard good things about Netbeans and TextMate which I'm thinking of trying. I use TextWrangler - its free :)

 

Hi Margaux thanks I am actually using Text Wrangler as well I just copied the code above from text edit though sorry.

Link to comment
Share on other sites

Ah yes that worked nicely thanks. Yikes one missing " can throw a wrench in your whole day can't it. Thanks again

 

Okay i found another error, other than changing Comments to comments for the text area name, you have a double quote missing from the handle_form.php echo statement. Correct code for handle_form.php is:

 

<!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>
<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$comments = $_REQUEST['comments'];
/* Not Used:
$_REQUEST['age']
$_REQUEST['gender']
$_REQUEST['submit']
*/
//Print the submitted information:
[b][color=#008000]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";[/color][/b]
?>
</body>
</html>

Link to comment
Share on other sites

hmm here is another one. How do you paste her with the colors Edward? When I paste my code here it is just black. Anyway can you see a problem here?

 

 

 

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

 

<?php

$name = $_REQUEST['name'];

$email = $_REQUEST['email'];

$comments = $_REQUEST['comments'];

 

/* Not Used:

$_REQUEST['age']

$_REQUEST['gender']

$_REQUEST['submit']

*/

 

//Create the $gender variable:

if (isset($_REQUEST['gender'])) {$gender = $_REQUEST['gender'];

} else {

$gender = NULL;

}

 

//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";

 

//Print a message based upon the gender value:

if($gender = = 'M') {

echo '<p><b>Good day, Sir!</b>

</p>';

} elseif ($gender = = 'F'){

echo'<p><b> Good day, Madam!

</b></p>';

} else { //No gender selected.

echo '<p><b>You forgot to enter

your gender!</b></p>';

}

 

 

 

 

?>

</body>

</html>

Link to comment
Share on other sites

Yes:

 

if($gender = = 'M') {

echo '<p><b>Good day, Sir!</b>

</p>';

} elseif ($gender = = 'F'){

echo'<p><b> Good day, Madam!

</b></p>';

 

needs to be changed to:

 

if($gender == 'M') {

echo '<p><b>Good day, Sir!</b>

</p>';

} elseif ($gender == 'F'){

echo'<p><b> Good day, Madam!

</b></p>';

 

So rather than having "= =" just remove the space from the middle so they become "==".

 

If you want the code to be colored like in my examples then you need to click the angles brackets icon <> in the window where you type your message text. The angle brackets is after image symbol and before the speech bubble.

Link to comment
Share on other sites

I know I could just cut and paste the code from the book
You're right to type all the code out as you'll remember it so much better. Whilst these kinds of errors are frustrating, you'll probably never make them again. I always used to forget the second = when making comparisons, now I never do (well almost never!).

 

Include your code between

[code]
[/code]

tags to make it more readable.

Link to comment
Share on other sites

One thing i forget to add, it would be a good idea to turn on display error's in your php.ini files on the server or ask your host to switch it on for you while you need to test your code. That way for yourself and for others here we would receive an error message and know which line of the script that the problem was present.

Link to comment
Share on other sites

Thanks again Edward my host has done this. Now I just need to make another error to test it out ;-)

 

One thing i forget to add, it would be a good idea to turn on display error's in your php.ini files on the server or ask your host to switch it on for you while you need to test your good. That way for yourself and for others here we would receive an error message and know which line of the script that the problem was present.

Link to comment
Share on other sites

So yes turning on the display errors has already worked for me as when I first ran this script I had an error on line 73 which I easily found. I also had another issue and I posted a big long speel about it here but I did figure it out I had $REQUEST instead of $_REQUEST. I am actually finding this PHP fun to work on now.

 

Link to comment
Share on other sites

So yes turning on the display errors has already worked for me as when I first ran this script I had an error on line 73 which I easily found. I also had another issue and I posted a big long speel about it here but I did figure it out I had $REQUEST instead of $_REQUEST. I am actually finding this PHP fun to work on now.

 

Glad to hear it is all working out for you. Edward

Link to comment
Share on other sites

 Share

×
×
  • Create New...