homepage Welcome to WebmasterWorld Guest from 54.237.54.83
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
RudyS




msg:3683445
 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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
Species:
<form id="form1" name="form1" method="post" action="">
<label>
<select name="species" id="species">
<option>ecoli</option>
<option>yeast</option>
</select>
</label>
</form>
<p>Concentration: </p>
<form id="form2" name="concentration" method="post" action="">
<label>
<input type="text" name="concentration" id="concentration" />
</label>
</form>
<p>Volume: </p>
<form id="form3" name="volume" method="post" action="">
<label>
<input type="text" name="volume" id="volume" />
</label>
</form>
<form id="form4" name="form4" method="post" action="cgi-bin/yield.pl">
<label>
<input type="submit" name="button" id="button" value="Submit" />
</label>
</form>
<p>&nbsp;</p>
</body>
</html>

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):
#!/usr/local/bin/perl
print "Content-type: text/html \n\n";
$concentration = "concentration";
$volume = "volume";
my $yield = "$concentration * $volume";
print "your yield is $yield";

 

lexipixel




msg:3695679
 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
-RudyS

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.

lexipixel




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


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

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.

perl_diver




msg:3695719
 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.

Kevin

RudyS




msg:3695724
 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

perl_diver




msg:3696084
 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.

lexipixel




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

It is possible to get both.

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

:)

RudyS




msg:3716180
 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 ...

RudyS

perl_diver




msg:3716308
 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

RudyS




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

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

thx

Rudy

perl_diver




msg:3716795
 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