Help - Search - Member List - Calendar
Full Version: Internal Server Error
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Ron Smith
Hi all,

I'm running:

'http://localhost/html/inputForm.html' which takes a first name and last name, and submits them to 'http://localhost/cgi-bin/query_string.cgi

I get a the following error:

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

The form settings are the following:

<form name="form1" id="form1" method="get" action="query_string.cgi">
The values of the URL are:
http://localhost/html/query_string.cgi?fna...h&submit=Submit
I did some moving of the files to get this to work but the '.cgi' file prints the underlying code from the above location. And, if I put both pages in the 'cgi-bin' directory, the ".html" page throws the following browser error;

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

Following is the code to the CGI script:

#!/wwww/perl/bin/perl.exe -wT
# input will be coming from "inputForm.html"
use strict;
use CGI qw(cgi);
use CGI::Carp qw(fatalsToBrowser);
print "content-type: text/htmlnn";
my %form;
my @pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach (@pairs) {
my ($name, $value) = split(/=/, $_);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}
print <<HTML;
<html>
<head><title> Output Form </title></head>
<body>
<center><h3> Form Output </h3></center><p></p>
HTML
foreach (keys %form) {
print "$_ = %form{$_}<br>";
}
print <<HTML;
</body>
</html>
HTML

Does anyone have any advice as to how to get this script to accept values from a ".html" page. It's probably something I'm unaware of. I'm just starting to get into CGI scripts.
I've since found a script that delivers what I want:
-----------------------------snip-3---------------------------
#!/www/perl/bin/perl.exe -wT
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
my $first_name = param('fname');
my $last_name = param('lname');
print header,
start_html('Form Output'),
h3({-align=>'center'}, 'Form Output'),
p;
print $_ . " - ". param($_) . br foreach param;
print end_html;
-----------------------------snip-3---------------------------

TIA

Ron

Chris Devers
On Tue, 5 Jul 2005, Ron Smith wrote:

QUOTE
Hi all,

I'm running:

'http://localhost/html/inputForm.html' which takes a first name and
last name, and submits them to
'http://localhost/cgi-bin/query_string.cgi

I get [Internal Server Error]

This is just a generic failure message. To find out what really went
wrong, you need to examine the contents of your Apache's error log. The
location for this is defined by the ErrorLog directive in httpd.conf.

If you want error messages to go back to the web browser as well as the
error log, you can use the CGI::Carp module, by putting the following
line at the top of your script:

use CGI::Carp qw[ fatalsToBrowser ];

This should produce more helpful error pages, but note that it also
gives away details about your code that the public shouldn't normally
have. Once you are done debugging, this line should be commented out
before making your site available to the public.

.... actually, on reading your script, I see that you *are* doing this,
but you're still getting a generic message. I have no idea why this
would be the case, maybe someone else on the list has an idea...

QUOTE
Following is the code to the CGI script:

#!/wwww/perl/bin/perl.exe -wT
# input will be coming from "inputForm.html"
use strict;
use CGI qw(cgi);
use CGI::Carp qw(fatalsToBrowser);
print "content-type: text/htmlnn";
my %form;
my @pairs = split(/&/, $ENV{'QUERY_STRING'});

WHY WHY WHY are you doing this?

The CGI.pm module has very nice methods for parsing the query parameters
and that's what nearly all CGI scripts should be using.

Nearly all CGI scripts I write start out with this block:

#!/path/to/perl -wT
use strict;
use CGI;
use CGI::Carp qw[ fatalsToBrowser ];
my $q = new CGI;
print $q->header;

If you just want to dump the environment, you can do something like this
next:

@pairs = $q->param;
foreach my $item ( $pairs ) {
print "$item is $q->param($item)";
}

Or equivalent -- there's a thousand ways to write that, but the idea is
generally always the same: get the parameter list from $q->param, then
walk the list you get back and do something with each item, like print
it or store it in another variable.

Details on working with this can be found in `perldoc CGI`, or if that
isn't available to you, you can get the same thing on the web at a site
like

http://www.perldoc.com/perl5.8.0/lib/CGI.html
http://search.cpan.org/dist/CGI.pm/CGI.pm

But in any case, for the love of Pete, don't parse CGI parameters by
hand, that hasn't been the right way to do it for nearly a decade :-)


--
Chris Devers

Charles K. Clarkson
Ron Smith <mailto:[Email Removed]> wrote:

: -----------------------------snip-2---------------------------
:
: Following is the code to the CGI script:
:
: #!/wwww/perl/bin/perl.exe -wT

This shebang line is in the wwww directory while the next
shebang is in the www directory. BTW, the ".exe" is not generally
included.


: I've since found a script that delivers what I want:
: -----------------------------snip-3---------------------------
: #!/www/perl/bin/perl.exe -wT


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist



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.