On Tue, 5 Jul 2005, Ron Smith wrote:

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

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/html\n\n";
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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to