Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Running CGI script

by anbutechie (Sexton)
on Apr 21, 2009 at 13:50 UTC ( [id://758972]=perlquestion: print w/replies, xml ) Need Help??

anbutechie has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have generated HTML code by the following script, then I copied the html code and saved it in notepad with extendtion .html. Then I opened the html file through IE browser, the page gets loaded correctly, On clicking the button the page redirected to http:\\localhost. I m expecting the statements under if(param()) function to be executed. Kindly let me know the way of execution CGI script

use CGI qw/:standard/;
print
header,
start_html('Simple Script'),
h1('Simple Script'),
start_form,
"What's your name? ",textfield('name'),p,

popup_menu(-name=>'color',-values=>'red','green','blue','chartreuse'),p,
submit,
end_form,
hr,"\n";

if (param) {
print
"Your name is ",em(param('name')),p,
"Your favorite color is ",em(param('color')),".\n";
}
print end_html;

Regards,
Anbarasu

Replies are listed 'Best First'.
Re: Running CGI script
by blue_cowdawg (Monsignor) on Apr 21, 2009 at 14:29 UTC
        Kindly let me know the way of execution CGI script

    Dear Monk,
    Running CGI is more than just creating HTML. You (or you system administrator) have to configure the server it is running on to deal with CGI and in the case of Perl/CGI you need to have handlers in place to deal with handing Perl off to an interpreter.

    If that is all equal and good you then need to ensure that the file permissions and ownership for the CGI script are set correctly depending on what environment you are running under. Windows, Unix and Linux play by different rules so you have to understand the environment you are running in.

    My advice to you is to start on the Tutorials page and look especially under CGI Programming and really read those pages and understand them. It will pay off in the long run.

    I'd also recommend you read and understand this page and some of the pages referenced in there and additionally this page and especially this page just to make your life here at the Monastery a lot easier.

    When you ask question please give as much complete information about what you are experiencing as you can. Log files from servers (which Corion mentioned) are one of my personal favorite ways of finding out what has gone wrong. Using [code] tags for your code as the anonymous monk mentioned is also a must.

    My intent is not to give you a hard time, but it is to help you understand how to properly get the most out of this community in terms of help and knowledge possible and hopefully in the future you can pay that forward by helping someone else out down the road.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Running CGI script
by Corion (Patriarch) on Apr 21, 2009 at 13:58 UTC

    You don't show us what error message you got, what webserver you're using and if it's configured correctly. You can help us help you better by telling us these things.

Re: Running CGI script
by scorpio17 (Canon) on Apr 21, 2009 at 15:00 UTC

    The way this script is supposed to work is as follows: The first time you access the URL, it displays a form. When you submit the form, the script gets called a second time, passing along your form data and displaying it.

    By capturing the output of the first run as HTML, you've created a "snapshot" of the first run's output. But when you click submit nothing happens, because the HTML is not a script.

    In simple terms, a web server does one of two things:
    1. if you request a file from inside the html directory, it just gives it to you. It's up to your browser to parse and render any html markup the file may contain.
    2. if you request a file from inside the cgi-bin directory, the web server runs the file and delivers the output (if any) to your browser.

    So, short answer: you put the output of your script in the html directory when what you need to do is put your script in the cgi-bin directory.

Re: Running CGI script
by Anonymous Monk on Apr 21, 2009 at 13:55 UTC
    Maybe if you used <code> tags like you've been told often ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://758972]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found