Help - Search - Member List - Calendar
Full Version: Form / CGI error
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Ron Smith
Hi all,

I'm getting an error when I submit the following html
form to a CGI script. I'm too inexperienced to spot
the error. So, I'm looking for help from the list.
I've already made the changes as suggested from the
error log, but I get the same error again. Does anyone
have any suggestions for me?

TIA
Ron

-------------------------------snip-1-From the
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">

<head>
<title>Form 4-21 Page</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" Cache-control: max-age=3 />
</head>

<script language="javascript">
function fname_focus() {
document.form4-21.fname.focus()
}
</script>

<body onload="javascript:fname_focus();">
<form name="form4-21" action="/cgi-bin/form4-21.cgi"
method="post">
First Name: <input type="text" name="fname"><br>
Last Name: <input type="text" name="lname"><br>
<br>
Favorite Color:<br>
<input type="radio" name="color"
value="red">Red<br>
<input type="radio" name="color"
value="blue">Blue<br>
<input type="radio" name="color"
value="green">Green<br>
<input type="radio" name="color"
value="yellow">Yellow<br>
<br>
Favorite Sport:<br>
<input type="checkbox" name="sports" value="hockey"
checked>Hockey<br>
<input type="checkbox" name="sports"
value="football">Football<br>
<input type="checkbox" name="sports"
value="baseball">Baseball<br>
<input type="checkbox" name="sports"
value="basketball">Basketball<br>
<input type="checkbox" name="sports"
value="golf">Golf<br>
<br>
<input type="submit" name="doit" value="send info">
</form>
</body>
</html>

-------------------------------snip----------------------------------

The following script is supposed to print out the
headings and values from the above form.

-------------------------------snip-2-From the CGI
script------------

#!/www/perl/bin/perl -wT

use strict;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print header;
print CORE::dump(); # <=========== This line was
originaly: print dump();

-------------------------------snip-2--------------------------------

-------------------------------snip-3-From the
browser---------------

Internal Server Error

The server encountered an internal error or
misconfiguration and was unable to complete your
request.

Please contact the server administrator,
admin@localhost and inform them of the time the error
occurred, and anything you might have done that may
have caused the error.

More information about this error may be available in
the server error log.

Apache/2.0.52 (Win32) PHP/4.3.10 mod_perl/1.99_18
Perl/v5.8.6 Server at localhost Port 80

-------------------------------snip-3---------------------------------

-------------------------------snip-4-From the error
log--------------

[Wed Jul 06 18:23:56 2005] [error] [client 127.0.0.1]
Premature end of script headers: form4-21.cgi,
referer: http://localhost/form4-21.html

[Wed Jul 06 18:23:56 2005] [error] [client 127.0.0.1]
[Wed Jul 6 18:23:56 2005] form4-21.cgi: dump() better
written as CORE::dump() at C:/www/cgi-bin/form4-21.cgi
line 7., referer: http://localhost/form4-21.html

[Wed Jul 06 18:23:57 2005] [error] [client 127.0.0.1]
r, referer: http://localhost/form4-21.html

[Wed Jul 06 18:23:57 2005] [error] [client 127.0.0.1]
This application has requested the Runtime to
terminate it in an unusual way., referer:
http://localhost/form4-21.html

[Wed Jul 06 18:23:57 2005] [error] [client 127.0.0.1]
Please contact the application's support team for more
information.r, referer:
http://localhost/form4-21.html

-------------------------------snip-4----------------------------------

TIA
Ron

Chris Devers
On Wed, 6 Jul 2005, Ron Smith wrote:

QUOTE
I'm getting an error when I submit the following html form to a CGI
script.

Let's focus on the script, not the HTML.

Once you've verified that the script works, at least on a basic level --
i.e. you can go to http://your-site/cgi-bin/your-script.cgi and get back
a non-error response -- *then* you can start thinking about the HTML.

QUOTE
#!/www/perl/bin/perl -wT

use strict;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print header;
print CORE::dump(); # <===== This line was originaly: print dump();

Okay, hold that thought...


QUOTE
---------snip-3-From the browser---------------

Internal Server Error

This continues to be useless. It's a generic error response from the web
server; it indicates nothing about what the actual problem was. That
said, with CGI::Carp's fatalsToBrowser, you should be getting useful
diagnostics in the web server response. Maybe it's hidden in a comment
or something, I don't know. In any case, the response you pasted doesn't
have any useful information in it, just as it didn't when you pasted it
to the list a few days ago :-)

QUOTE
--------------snip-4-From the error log--------------

[Wed Jul 06 18:23:56 2005] [error] [client 127.0.0.1]
Premature end of script headers: form4-21.cgi,
referer: http://localhost/form4-21.html

Okay, now we're getting somewhere.

"Premature end of script headers" is generally a tell-tale sign that the
CGI script never sent back the mandatory content-type declaration. I'm
not clear why this isn't working, as the `print header;` line you have
should do this, but in any case you can ignore CGI.pm for a moment and
just put the needed line in directly, like so:

#!/www/perl/bin/perl -wT

use strict;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/plainnn";
print "Okay, at least this worked.n";

If the code above works, then you can amend it to use your CORE line:

#!/www/perl/bin/perl -wT

use strict;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/plainnn";
print CORE::dump();

Now then, why on earth are you trying to dump core?

If you just want to output the environment, this is a clumsy way to do
it. Something like this would work just fine:

#!/www/perl/bin/perl -wT

use strict;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/plainnn";

print "Environment variable dump:n";
foreach $key ( sort keys %ENV ) {
print "$key: $ENV{$key}n";
}

That should work, and as it isn't dumping core, it might even behave :-)



--
Chris Devers

Ron Smith
--- Chris Devers <[Email Removed]> wrote:

QUOTE
On Wed, 6 Jul 2005, Ron Smith wrote:

I'm getting an error when I submit the following
html form to a CGI
script.

Let's focus on the script, not the HTML.

Once you've verified that the script works, at least
on a basic level --
i.e. you can go to
http://your-site/cgi-bin/your-script.cgi and get
back
a non-error response -- *then* you can start
thinking about the HTML.

#!/www/perl/bin/perl -wT

use strict;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print header;
print CORE::dump(); # <===== This line was
originaly: print dump();

Okay, hold that thought...


---------snip-3-From the browser---------------

Internal Server Error

This continues to be useless. It's a generic error
response from the web
server; it indicates nothing about what the actual
problem was. That
said, with CGI::Carp's fatalsToBrowser, you should
be getting useful
diagnostics in the web server response. Maybe it's
hidden in a comment
or something, I don't know. In any case, the
response you pasted doesn't
have any useful information in it, just as it didn't
when you pasted it
to the list a few days ago :-)

--------------snip-4-From the error
log--------------

[Wed Jul 06 18:23:56 2005] [error] [client
127.0.0.1]
Premature end of script headers: form4-21.cgi,
referer: http://localhost/form4-21.html

Okay, now we're getting somewhere.

"Premature end of script headers" is generally a
tell-tale sign that the
CGI script never sent back the mandatory
content-type declaration. I'm
not clear why this isn't working, as the `print
header;` line you have
should do this, but in any case you can ignore
CGI.pm for a moment and
just put the needed line in directly, like so:

#!/www/perl/bin/perl -wT

use strict;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/plainnn";
print "Okay, at least this worked.n";

If the code above works, then you can amend it to
use your CORE line:

#!/www/perl/bin/perl -wT

use strict;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/plainnn";
print CORE::dump();

Now then, why on earth are you trying to dump core?

This was just an exercise out of a book. I gave your
suggestion a try and worked through the lines and got
it to work. I still get the error with 'dump()'
though. I finally moved on to the following, whiched
worked fine:

#!/www/perl/bin/perl -wT

# use strict;
use CGI qw(:standard);
# use CGI::Carp qw(fatalsToBrowser);
print header;

my $first_name = param('fname');
my $last_name = param('lname');
my $fav_color = param('color');

print qq(Hello, $first_name $last_name.<br />);
print qq(Your favorite color is: $fav_color<br />);

Thanks for the suggestion. :-)

Ron

QUOTE

If you just want to output the environment, this is
a clumsy way to do
it. Something like this would work just fine:

#!/www/perl/bin/perl -wT

use strict;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/plainnn";

print "Environment variable dump:n";
foreach $key ( sort keys %ENV ) {
print "$key: $ENV{$key}n";
}

That should work, and as it isn't dumping core, it
might even behave :-)



--
Chris Devers



PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.