LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   fetching variables with .cgi (https://www.linuxquestions.org/questions/linux-newbie-8/fetching-variables-with-cgi-426954/)

Tillus 03-21-2006 10:59 AM

fetching variables with .cgi
 
I'm trying to get my script to echo my input to a form back to me. I use this line:

print &PrintVariables(%in);

The problem is that when the script gets to this line, it halts and nothing else will be executed. So I wonder:

am I trying to retrieve the variables in the wrong way? I'm using perl 5.8.8.


Thanks for your help!

Tillus

theNbomr 03-21-2006 11:19 AM

Here you go...

Code:

#! /bin/perl -w

use    strict;
use    CGI::Carp qw(fatalsToBrowser);
use    CGI qw/:all/;
use    DBI;

    my $query = CGI::new();
    print "Content-Type: text/html\n\n";

    print "<html>\n";
    print "<head>\n";
    print "<title>Web Server Log Query</title>\n";
    print "</head>\n";

    print "<HTML><BODY>\n";

    print "<H1><CENTER>CGI Multiforms test</CENTER></H1>\n";

    #
    #  Print every spec of information...
    #
        print "<H6>\n";
        foreach my $EnvVar ( sort( keys( %ENV ) ) ){
            print "<br>$EnvVar = $ENV{$EnvVar}\n";
        }
        print "</H6>\n";

        my @Names = $query->param;
        foreach my $Name (@Names ){

            my @Values = $query -> param( $Name );

            foreach my $Value ( @Values ){
                print "<br>NAME : $Name  :  VALUE : <PRE>\"$Value\"</PRE>\n";
            }
        }

    print "</BODY></HTML>";

--- rod.

Tillus 03-21-2006 12:31 PM

I tried running your script, but got a Error 500, Premature end of script headers.

To be as clear as possible I Include the hole script:

#!/usr/bin/perl
use CGI;
CGI::ReadParse();

print "Content-Type: text/html\n\n";
print "<HTML><HEAD><TITLE>";
print "Variable Listing";
print "</TITLE></HEAD><BODY>";
print "<H1>Variables Passed From Form</H1>";
print &PrintVariables(%in);This is the difficult line
print "<P>dONE";
print "</BODY></HTML>";


Lots of love

Tillus

theNbomr 03-22-2006 10:27 AM

Hmm. I just re-tried the script, and it ran fine. Did you copy it exactly, make it an executable perl script, and place it in your server's cgi-bin directory? I guess you would have to modify the shebang line to point at your /usr/bin/perl.

WRT your script, this line:

Quote:

print &PrintVariables(%in);This is the difficult line
makes no sense. You are passing a reference to an undefined subroutine that is taking an undefined hash as an argument. Where do you think the values for these are supposed to come from?

Also, in perl *ALWAYS*

use strict;

... and ...

#! /usr/bin/perl -w

These things are there to help you find bugs before you post to the internet for help.

--- rod.


All times are GMT -5. The time now is 02:10 AM.