CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Getting variable from url

 



Rivotti
User

Mar 28, 2000, 5:05 AM

Post #1 of 10 (2024 views)
Getting variable from url Can't Post

I'm using this line to open passo5.cgi with the user=2810211120001110:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

http://www.contifax.com/cgi-bin/curriculum/passo5.cgi?user=2810211120001110</pre><HR></BLOCKQUOTE>

And in "passo5.cgi" I use:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

#!/usr/bin/perl

use CGI qw( :standart );

print "Content-type: text/html\n\n";

$user= new CGI->param('user');
print $user;
require "$user.pl";
...</pre><HR></BLOCKQUOTE>

And nothing happens. Now, if a use the line in the browser command line, "passo5.cgi" runs. What is happening?
Why $user="" when I run the program from another program. I am doing something wrong?

Rivotti


japhy
Enthusiast

Mar 28, 2000, 8:44 AM

Post #2 of 10 (2024 views)
Re: Getting variable from url [In reply to] Can't Post

Ah ha, my suspicions were right. The variable $user is empty.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


# do it the function-oriented way...
use CGI ':standard';
$user = param('user');

# or the object oriented way
use CGI;
$q = new CGI;
$user = $q->param('user');

# or a silly OO way
use CGI;
$user = CGI->new->param('user');

# or, just as silly, and what you were trying to do
use CGI;
$user = (new CGI)->param('user');
</pre><HR></BLOCKQUOTE>


Cure
User

Mar 28, 2000, 2:51 PM

Post #3 of 10 (2024 views)
Re: Getting variable from url [In reply to] Can't Post

hi

CGI.pm can be used in two distinct modes called function-oriented and object-oriented. In the function-oriented mode, you first import CGI functions into your script's namespace, then call these functions directly: ->use CGI qw(:standard);


In the object-oriented mode, you use CGI; without specifying any functions or function sets to import. In this case, you communicate with CGI.pm via a CGI object. ->use CGI;
$q = new CGI;

I have never used the function-oriented mode because its load all the standard function into your cgi-script(making compile time longer)


The best route is object-oriented mode.


Cure



[This message has been edited by Cure (edited 03-28-2000).]


Rivotti
User

Mar 28, 2000, 3:23 PM

Post #4 of 10 (2024 views)
Re: Getting variable from url [In reply to] Can't Post

It's dificult to me to explain better ( I'm Portuguese, English is not my mother language ), But I'll try:

I have this file named "passo4.cgi" that save a temp file, named $user to the server and print out a form that will call "passo5.cgi" ("Passo" means "Step" in portuguese).

Hereīs a piece of code of "passo4.cgi":

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

#!/usr/bin/perl

use CGI qw( :standart );

print "Content-type: text/html\n\n";

# This section grab all parameters from the previous form "passo3.cgi"

$academicas = new CGI->param("academicas");
$habilitacoes = new CGI->param("habilitacoes");
$profissional = new CGI->param("profissional");
$campoextra1 = new CGI->param("campoextra1");
$campoextra2 = new CGI->param("campoextra2");
$escolha1 = new CGI->param("escolha1");
$escolha2 = new CGI->param("escolha2");
$escolha3 = new CGI->param("escolha3");
$escolha4 = new CGI->param("escolha4");
$template_imagem = new CGI->param("template_imagem");
$template_css = new CGI->param("template_css");
$n="3";
my $j;

# This section will create a number that will be temp file name

$time= gmtime;
$time=~ s/\D//g;
if (campoextra1 ne "")
{ $extra="0" }
else
{ $extra=$campoextra2 }
$user= $time.$academicas.$habilitacoes.$profissional.$extra;

# now the form is printed out

print '<body>

<form action="http://www.contifax.com/cgi-bin/curriculum/passo5.cgi?user='.$user.'
" method="post">
<div align="center">
<center>
<table border="0" cellPadding="0" cellSpacing="0" width="400">

...

# foward the program will create the temp file as "$user.pl"

...
</pre><HR></BLOCKQUOTE>

Are you still awake?
Ok! Now, in "passo5.cgi", I use the following code:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl

use CGI qw( :standart );

print "Content-type: text/html\n\n";

$user = new CGI->param('user');
require "$user.pl";

...
</pre><HR></BLOCKQUOTE>

I assume that everything is correct.
Can you explain why "passo5.cgi" can't use the variable $user in the browser ? And why it works when a use the same code directly in the commad line ?

If you want, you can see the program running in here.
This program's language is Portuguese but you just need to push the button "Continuar" at the end of each form.

As you will see, whem the browser opens the "passo5.cgi" the url is correct but nothing appears.

Thank you for your time and patience.

Another thing: When the Browser calls "passo5.cgi" appears, in the command linem something like this:
http://www.contifax.com/cgi-bin/curriculum/passo5.cgi?user=2900265920001110
The funny thing is that it works if you push this link

now try to add & before the word user.
It works. But if I use the same thing in the code of "passo4.cgi" the program doesn't work. It will appear in the command line:
http://www.contifax.com/cgi-bin/curriculum/passo5.cgi?&user=2900265920001110

And doesn't work. But if i delete the & it will work again.

Argh, maybe I'm gettin perl poisonning...

Rivotti

[This message has been edited by Rivotti (edited 03-28-2000).]


japhy
Enthusiast

Mar 28, 2000, 5:52 PM

Post #5 of 10 (2024 views)
Re: Getting variable from url [In reply to] Can't Post

Your problem is still the same. You are doing:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$value = new->CGI param('something');
</pre><HR></BLOCKQUOTE>

Don't do that. Do:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$value = param('something');
</pre><HR></BLOCKQUOTE>

Also, you're importing from CGI.pm incorrectly. The correct method is:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use CGI ':standard'; # not ':standart' <-- typo
</pre><HR></BLOCKQUOTE>

Please re-read my original post to see what other methods are available.


Cure
User

Mar 28, 2000, 10:35 PM

Post #6 of 10 (2024 views)
Re: Getting variable from url [In reply to] Can't Post

There ARE 2 ways to pass-variable information...

1.THROUGH A LINK(s).
2.USING HIDDEN TAG(s).

Cure


Rivotti
User

Mar 29, 2000, 2:59 AM

Post #7 of 10 (2024 views)
Re: Getting variable from url [In reply to] Can't Post

Iīve already changed the import method to
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

use CGI ':standard';</pre><HR></BLOCKQUOTE>
I don't know how I've missed that...

Still de program doesnīt work. I've tried all the ways you gave me ( I even deleted the cache in the browser ) but itīs the same sad history.

The fact that I'm calling that url with a Post menthod doesn't change the way a get the data?

Maybe this is the result from another stupid error like the "standart" erro. But it seems all right to me...

I simply don't get...

Thank you in advance for your help and patience

Rivotti


brian.hayes
User

Mar 29, 2000, 4:55 AM

Post #8 of 10 (2024 views)
Re: Getting variable from url [In reply to] Can't Post

Just use this:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use CGI;
my $q = new CGI;

$user = $q->param('user');

undef $q; ##When your done with it within the page.

</pre><HR></BLOCKQUOTE>

Also this is wrong

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



<form action="http://www.contifax.com/cgi-bin/curriculum/passo5.cgi?user='.$user.'" method="post">

</pre><HR></BLOCKQUOTE>

Take out the quotes and ..

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



<form action="http://www.contifax.com/cgi-bin/curriculum/passo5.cgi?user=$user" method="post">

</pre><HR></BLOCKQUOTE>

Let us know..
Brian Hayes


Rivotti
User

Mar 29, 2000, 6:31 AM

Post #9 of 10 (2024 views)
Re: Getting variable from url [In reply to] Can't Post

Hi Brian Hayes:

Thanks for your reply.
Still not working. I know the code is correct because if you use directly
http://www.contifax.com/cgi-bin/curriculum/passo5.cgi?user=2915162920001110

it works. See? That is not my problem. The problem is why it doesn't work when the program is started by the previous program "passo4.cgi".

I hope you're understanding. I'm trying to creat an aplication that calls

first: "passo3.cgi"
this program create a form that will call for "passo4.cgi"

second: "passo4.cgi"
this file process the data from "passo3.cgi", create a temp file named $user.pl and create a form that will call for "passo5.cgi?user=$user".

third_ "passo5.cgi"
this file reads $user, require "$user.pl" and process the data from "passo4.cgi"

If you want you can see this operation running here
Just push the button "Continuar", in the end of each form, to reach passo5.cgi

I hope I'm not getting crazy!
Rivotti

[This message has been edited by Rivotti (edited 03-29-2000).]


Rivotti
User

Mar 29, 2000, 7:35 AM

Post #10 of 10 (2024 views)
Re: Getting variable from url [In reply to] Can't Post

Thank you all for helping. I've been reading some information about querying and I finally found what I was looking for. I just added

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$user=$ENV{'QUERY_STRING'};</pre><HR></BLOCKQUOTE>

to "passo5.cgi" and it works.

I thing that, when processing a form created by another CGI program, the next program doesnīt read the variables in the url.

Again, thank you all for the help.
Rivotti

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives