Forum Moderators: coopster & phranque

Message Too Old, No Replies

Simple CGI script

         

tyl2001

6:37 pm on Oct 27, 2003 (gmt 0)



I am writing a simple CGI script, but I need help from you guys. Currently, I wrote two html pages: test.htm and test1.htm.

I want user first load test.htm, choose the answer then click next to the second question. Then the result will be the sum of the two choices.

I have three problems here:
1. How can I write the CGI code to jump to second page?
2. How can I perform the calculation?
3. How can I save the results in a txt file?

Thanks very much.

[edited by: sugarkane at 7:28 pm (utc) on Oct. 27, 2003]
[edit reason] No URLs please. Thanks [/edit]

protheus99

9:36 pm on Oct 28, 2003 (gmt 0)

10+ Year Member



This one i think i can handle, First u will need a form in your 1st page with the two value in different <input> tags make sure u have them named with like this
<input name="Value1"> and <input name="Value2">
the form needs to go to the cgi file u are creating right now.

u will start your cgi as usual

#!/usr/local/bin/perl
use CGI;
my $q = new CGI;
#retreive the values
my $Value1 = $q->param('Value1');
my $Value2 = $q->param('Value2');
$Result = $Value1 + $Value2;

#now u need to write it out in a file and create ur 2nd html file, u have two options when creating the html file u can eighter create it dynamicaly then retreive it or just output the data that u wanted in the cgi itself.

#Creating the result file
open (File,">results.txt") ¦¦ die " impossible d'ouvrir data";
print File $Results;
close File;

#Output the data on the screen
print $query->start_html("The result is"); #This will be the title of ur page
print "<h1>The Result is $Results</h1>";
print "</body></html>";

that should be it i think but just in case try it out ...

.: protheus :.