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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I pass $variables from one cgi to another

Status
Not open for further replies.

calabama

Programmer
Feb 19, 2001
180
US
How do I pass scalar variables when another script is being executed?

Thanks Tim In the begining
Let us first assume that there was nothing to begin with.
 
How do you mean when another script is being executed? Do you mean by a system call, by a subroutine call, or what?
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
How do I pass $a from the first cgi(A) and use the variable $a in another cgi(B).

I really did not want to write the variable from cgi(A) to a PM file and then acces from cgi(B).

I thought that $a could be passed into cgi(B) from cgi(A)some other way. In the begining
Let us first assume that there was nothing to begin with.
 
You can do something like this:
<input type=&quot;hidden&quot; name=&quot;B&quot; value=&quot;A&quot;>
(Embed this in the HTML output by cgi(a).)
Then you can simply access it like any other variable
when processing cgi(b), as so:
$b = $q->param('B');
# $b=='A' in the above example.
-- Glenn

 
Easy solution for you, I had this same problem,

You can pass with form input and you can pass with a hyperlink
To pass default data just use ?$variable and then pick up in the environmental variable in script b
Couple easy ways to do this

Form Method
print &quot;<FORM ACTION=add2.cgi?$user METHOD=POST>&quot;;
In this example I am sending the form data and also the $user variable to another script.MAKE SURE YOU DONT PUT QUOTES AROUND ANYTHING INBETWEEN THE < > OR YOU WILL GET AN ERROR

Hyperlink Method
print &quot;<A HREF='add.cgi?$user'>YES</A>&quot;;
iN THIS EXAMPLE WHEN THE PERSON CLICKS ON THE YES LINK, IT SEND THE $USER VARIABLE TO THE NEXT SCRIPT

Next, how to retrieve this data in the next script. It is stored in an enviromental variable named &quot;Query String&quot;

#Script B
$variable =$ENV{'QUERY_STRING'};

Voila, your variable you passed from script A, is stored in the enviromental variable Query String which you then pick up in the next script and assign to another variable for use.
 
Thanks Quan

This is really a lot of help with great choices.

Tim In the begining
Let us first assume that there was nothing to begin with.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top