homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

This 40 message thread spans 2 pages: < < 40 ( 1 [2]     
creating a cgi script for an html input form

 8:02 pm on Jun 25, 2008 (gmt 0)

i tried to write a cgi script that would calculate $yield after someone entered numbers into input forms in an html script. here is the html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<form id="form1" name="form1" method="post" action="">
<select name="species" id="species">
<p>Concentration: </p>
<form id="form2" name="concentration" method="post" action="">
<input type="text" name="concentration" id="concentration" />
<p>Volume: </p>
<form id="form3" name="volume" method="post" action="">
<input type="text" name="volume" id="volume" />
<form id="form4" name="form4" method="post" action="cgi-bin/yield.pl">
<input type="submit" name="button" id="button" value="Submit" />

i had my boss help me out to write a simple script that works in command prompt, it is basically what i want to translate into an html form and a cgi script:

print "\ninput your concentration in ng/ul\n\n";
$concentration = <STDIN>;
print "input your volume in ul\n";
$volume = <STDIN>;
print "your yield is\n";

print ($volume * $concentration);

i do not know how to write the cgi script for this...i've been taking shots in the dark and here is what i've tried (it doesn't work):
print "Content-type: text/html \n\n";
$concentration = "concentration";
$volume = "volume";
my $yield = "$concentration * $volume";
print "your yield is $yield";



 7:23 pm on Jul 10, 2008 (gmt 0)

when i type a sequence in the input box it goes to the correct link of the cgi script but i get "internal server error" and also a 404 not found. the problem lies in the cgi script. my boss said that i should try to figure out how to write function oriented scripts

Your statement makes no sense:

500 Internal Server Error is a problem with the script
404 Not Found - means it never found the script.

(the 404 is probably due to the fact that you have no action specified for your form --- the 500 can be as simple as a missing semi-colon or bracket)..

The two error codes would not be returned for the same issue / problem...

As for your boss telling you to write function oriented scripts, yes -- writing functions is helpful when you need to re-use code, but since you can't get a simple CGI script to run, (and don't seem to understand the underlying principals of CGI), the fact that the script's functionality is coded inline as opposed to being a true "function" (which compares to a "sub-routine" in other programming languages), makes no difference at all.

Did you upload EXAMPLE2.CGI to a webserver and get it to execute? Please give a simple "YES" or "NO" answer... you are straying from the issue.


 7:44 pm on Jul 10, 2008 (gmt 0)

Your Sequence:
<form id="form1" name="form1" method="post" action="">
<input type="text" name="$inputlength" id="$inputlength" />
<form id="form2" name="form2" method="post" action="cgi-bin/tmcalculator.cgi">
<input type="submit" name="button" id="button" value="Submit" />

I just noticed you are still not even designing your form properly.. Perl_diver showed you by example and explained it many messages ago in this thread.

If you are not going to try to learn from what others share with you here, you might want to just buy a book, (I suggest "The Perl Cookbook" by NAthan Torkington)... you can get it at a library if you don't want to buy it. It will teach you by example... but you need to understand HTML, HTML FORMS, PERL, CGI, FTP, as well as basic programming principals like data modeling and flow.


 8:25 pm on Jul 10, 2008 (gmt 0)

I feel for you Rudy, and nothing you said previosuly offended me. I found your previous comments about my teaching methods to be humorous. Once again, I want to wish you luck and I sincerely hope you figure it out. No hard feelings on my part.



 8:31 pm on Jul 10, 2008 (gmt 0)

i figured out how to modify the example from lexipixel (helloworld 2) to calculate the length of the name. no help needed until further notice :) thanks


 5:55 am on Jul 11, 2008 (gmt 0)

Your statement makes no sense:

500 Internal Server Error is a problem with the script
404 Not Found - means it never found the script.

It is possible to get both. Many servers search for a custom error document to display when a server error occurs, and if none is found it throws the 404 error meaning the custom error document was not found.


 8:16 pm on Jul 11, 2008 (gmt 0)

It is possible to get both.

I stand corrected... even though I'm sitting.



 12:59 am on Aug 6, 2008 (gmt 0)

hi guys, Im back online ... the summer intern who was using my account has given up on this problem but there are two other students tackling this problem for August ... I finally read through this long thread and want to thank you all sincerely for putting up with "me" ... this all happened because I was told that previous attempts to register with yahoo or gmail accounts had been rejected or whatever ... though one of the new students has an account ... he is making a presentation on Friday of his work to the other Howard Hughes Medical Institute Interns ... one of the slides (entitled "Salvation") has a graphic of the WebmasterWorld logo in the background and acknowledges Perl_Diver and Phranque for helping him (his sign-in is medranoenrique) ... sorry for all the bother ... hopefully next week some useful scripts will be running on the website (an academic institution) ...

I was told that if the perl script can be designed to take all its arguments from the command line, then it is a "simple matter" to run it with a CGI script getting arguments from the submit button on an HTML form? sound reasonable? anyway medranoenrique has it set up that way (like $name = $ARGV[0]; $sequence = $ARGV[1];) and he is spending time with another student to make it work ...

again, sorry for all the bother "I" caused ...



 5:32 am on Aug 6, 2008 (gmt 0)

Its relatively easy to convert a command line script into a CGI based input script, but CGI scripts run in an inherently insecure environment and you have to use more security because of that. The first rule of CGI programming is:

never trust user input

the second rule is:

all user input should be treated like poison

the third rule is:

see the first and second rule


 1:36 pm on Aug 6, 2008 (gmt 0)

maybe they should put a password restriction so that only "trusted users" can input values?




 5:24 pm on Aug 6, 2008 (gmt 0)

That is only to restrict who can access the script, not what they send to the script. Not a bad idea though to use authentication (ID/password).

This 40 message thread spans 2 pages: < < 40 ( 1 [2]
Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved