LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Not able to retrieve the session variables (https://www.linuxquestions.org/questions/linux-newbie-8/not-able-to-retrieve-the-session-variables-4175523538/)

zak100 10-28-2014 01:30 AM

Not able to retrieve the session variables
 
Hi,
I have written a cgi-script in perl i.e testsession.pl . It has two edit boxes. I am storing the values of these text boxes in session variables. But when i am trying to retrieve their values in another script 'insertbyAdmin.pl' i am not able to print the values of session variables in the second script.
The code for 'testsession.pl' is:

Code:

[root@localhost cgi-bin]# cat testsession.pl
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI;
use CGI::Session;
use DBI;
my $ID;
my $Name;
my $Phone;
my $cgi;
my $session;
my $cookie;
my $sth;
my $dbh;
my $row;

$cgi = new CGI;
$session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'});
$cookie = $cgi->cookie(CGISESSID => $session->id);

print <<HTML_PAGE;
<html>
<head>
<title>Admin Page: Display Records, Edit, Delete and Insert </title>
</head>
<body>

<FORM method = "post" action="/cgi-bin/insertbyAdmin.pl">
<TABLE BORDER ="0">
<TR>
<TD>Name</TD>
<TD><input type="text" name="Name" value=""></TD>
</TR>
<TR>
<TD>Phone</TD>
<TD><input type ="text" name="Phone" value=""></TD>
</TR>
<TR>
<TD><h1>Insert Next Record: Select Yes or No </h1></TD></TR>
</TR>
<TR>
<TD><li><Input Type="radio" name="Yes" value="Yes" unchecked>Yes </TD>
</TR>
<TR>
<TD><li><INPUT TYPE="radio" name="No" value="No. Return to Login" unchecked>No</TD>
</TR>
<TR><TD COLSPAN="2" ALIGN="RIGHT">
<input type="submit" name="submit" value="insertNext">
</TD></TR></TABLE></FORM>
HTML_PAGE

$Phone = $cgi->param('Phone') || '';
$Name = $cgi->param('Name') || '';

$session->param(name1, $Name);
$session->param(Phone1, $Phone);

print<<HTML_PAGE;
</table>
</BODY></HTML>
HTML_PAGE
exit;




[root@localhost cgi-bin]#

and the insertbyAdmin.pl is given below:

Code:

[root@localhost cgi-bin]# cat insertbyAdmin.pl
#!/usr/bin/perl
use DBI;
use CGI;
use CGI::Session;

my $ID;
my $Name;
my $phone;
my $cgi;
my $session;
my $cookie;
my $sth;
my $dbh;
my $row;
my $username;
my $password;

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

$retval = time();
$local_time = gmtime( $retval);
print "Local time = $local_time\n";
 
print <<HTML_PAGE;
<html>
<head>
<title> A simple Perl CGI </title>
</head>
<body>
<h1> A Simple Perl CGI </h1>
<p> Hello World</p>
HTML_PAGE
 
$cgi = new CGI;
my $session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'});
 
$username = $session->param("name1");
$password = $session->param("Phone1");
print "$username";
print "$password";
print<<HTML_PAGE;
</body></html>
HTML_PAGE
exit;
[root@localhost cgi-bin]#


The output of insertbyAdmin.pl is :

The output of insertbyAdmin.pl is:

Code:

Local time = Tue Oct 28 06:17:14 2014
A Simple Perl CGI
Hello World

Somebody please help me with this problem.

Zulfi.

rigor 10-28-2014 03:25 AM

Hi zak100!

I'm probably missing something, but it almost looks like you're using "bare words" in testsession.pl to designate the params, yet strings in insertbyAdmin.pl to refer to what I'm taking to be the same params.

If so, is that valid?

zak100 10-28-2014 04:00 AM

Hi,
Thanks for your response. I think you are right. There is some proper way to assign names to HTML objects like text box and others. But i dont know at this point. Kindly guide me.

Zulfi.


All times are GMT -5. The time now is 02:13 AM.