On Thu, 4 May 2000, Chad Tower wrote:
>
> Hi... been doing perl a long time, new to CGI. I'm trying to do
> something very simple here... take a simple form input via POST and
> print the results out to the browser. The code works when I use GET,
> but when I use POST it never gets through the interpreter and I'm not
> sure how to debug that. Here is the code:
>
>
> #!/usr/bin/perl
>
> $CRLF = "\x0d\x0a";
>
> print "Content-type: text/html$CRLF$CRLF";
>
>
> # printvars
> #
> # diagnostic to print the environment and CGI variables
> #
> sub printvars {
> print "<p>Environment:<br>\n";
>
> foreach $e (sort keys %ENV) {
> print "<br><tt>$e => $ENV{$e}</tt>\n";
> }
>
> print "<p>Form Vars:<br>\n";
>
> foreach $name (sort keys %query) {
> print "<br><tt>$name => [$query{$name}]</tt>\n";
> }
> }
>
>
> sub getquery {
> my $method = $ENV{'REQUEST_METHOD'};
> my ($query_string, $pair);
> my %query_hash;
>
> $query_string = $ENV{'QUERY_STRING'} if $method eq 'GET';
> $query_string = <STDIN> if $method eq 'POST';
>
> foreach $pair (split(/&/, $query_string)) {
> $pair =~ s/\+/ /g;
> $pair =~ s/%([\da-f]{2})/pack('c',hex($1))/ieg;
> ($_qsname, $_qsvalue) = split(/=/, $pair);
> $query_hash{$_qsname} = $_qsvalue;
> }
>
> return %query_hash;
> }
>
> #&printvars;
> %query_hash = &getquery;
>
> $title = $blue ? "I'm Blue" : "Big Light in Sky";
>
> $listening = $listening? "Yes" : "No";
> $blue = $blue ? "Yes" : "No";
>
> print <<HERE;
>
> <title>$title</title>
>
> <table>
> <tr><th align=right>Name: <td>$query_hash{name}
> <tr><th align=right>Age: <td>$query_hash{age}
> <tr><th align=right>Are they listening? <td>$listening
> <tr><th align=right>Are you Blue? <td>$blue
> <tr><th align=right>This form is: <td>$query_hash{formis}
> <tr><th align=right>This form is also: <td>$query_hash{formalso}
> <tr><th align=right>The secret word is: <td>$query_hash{info}
>
> </table>
>
> HERE
>
> exit;
>
You need to do a binmode(STDOUT) prior to your first print.
Or you need to take out the \x0d part of the $CRLF variable.
Also in the getquery sub after the check for $method eq 'POST', insert
this code:
unless($query_string) {
print <<END;
<HTML>\r
<BODY>\r
Error \$query_string undefined. \$method: $method\r
</BODY>\r
</HTML>\r
END
exit;
}
**** [EMAIL PROTECTED] <Carl Jolley>
**** All opinions are my own and not necessarily those of my employer ****
---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
[EMAIL PROTECTED]
For non-automated Mailing List support, send email to
[EMAIL PROTECTED]