LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-21-2006, 11:59 AM   #1
Tillus
Member
 
Registered: Dec 2004
Posts: 55

Rep: Reputation: 15
Question 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
 
Old 03-21-2006, 12:19 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 03-21-2006, 01:31 PM   #3
Tillus
Member
 
Registered: Dec 2004
Posts: 55

Original Poster
Rep: Reputation: 15
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
 
Old 03-22-2006, 11:27 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.

Last edited by theNbomr; 03-22-2006 at 11:39 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Threads synchronisation problem (mutex variables and contitional variables) zahadumy Programming 6 12-07-2005 01:30 PM
bizarre python behavior - simple cgi variables SerfurJ Programming 2 04-14-2004 03:58 PM
CGI Variables cleared by SuSEfirewall2 fwalthard Linux - Networking 1 06-26-2003 01:33 PM
Shel scripting: variables pointing to variables and case Dark_Helmet Programming 5 06-08-2003 12:07 PM
http://www.burstnet.com/cgi-bin/ads/ad7954a.cgi/3980/RETURN-CODE rverlander LQ Suggestions & Feedback 1 06-07-2002 08:35 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration