Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pass variable to cgi (through url?)

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
0
0
here is the code...


**
count.cgi

#!/usr/local/bin/perl

my $cfile = "./data/count.dat";
open (COUNTER, "$cfile");
my $count = <COUNTER>;
close (COUNTER);
$count += 1;
open (COUNTER, &quot;>$cfile&quot;);
print COUNTER (&quot;$count&quot;);
close (COUNTER);

print&quot;Location:

**

i would like to pass a value to the program, then use the if/else conditional based on that value...

any ideas?

since count.cgi is called through a link, i though i could use ../count.cgi?id=val1 but that didn't seem to work.
 
okay, i added the @ARGV...


**
count.cgi


#!/usr/local/bin/perl

my $v = @ARGV;

my $cfile = &quot;./data/$v.dat&quot;;
open (COUNTER, &quot;$cfile&quot;);
my $count = <COUNTER>;
close (COUNTER);
$count += 1;
open (COUNTER, &quot;>$cfile&quot;);
print COUNTER (&quot;$count&quot;);
close (COUNTER);

print&quot;Location:
**

the the .dat file that it opens is 1.dat, no matter what i put after the ?...

ex.

count.cgi?p
count.cgi?test


is that right? help please...

spewn
 
I don't know what @ARGV does but here's what I do when passing information through with the query string.

$query_string = $ENV{'QUERY_STRING'};

then you have id=val1 inside query string and you can split it at the equals sign or do whatever it is you want to do with it. Age: 17
School: Alberta Distance Learning Center
Location: British Columbia, Canada
If at first you dont't succeed, try, try again. - programmer's motto.
 
easy enough...thanks!

-spewn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top