LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-28-2014, 02:30 AM   #1
zak100
Member
 
Registered: Jul 2009
Posts: 225

Rep: Reputation: 2
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.

Last edited by zak100; 10-28-2014 at 02:31 AM.
 
Old 10-28-2014, 04:25 AM   #2
rigor
Member
 
Registered: Sep 2011
Posts: 212

Rep: Reputation: Disabled
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?
 
Old 10-28-2014, 05:00 AM   #3
zak100
Member
 
Registered: Jul 2009
Posts: 225

Original Poster
Rep: Reputation: 2
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP session variables bluegospel Programming 5 12-13-2012 08:53 PM
[SOLVED] apache/ff/ie and session variables puzzle Wim Sturkenboom Linux - Server 2 08-25-2009 04:17 AM
pass & retrieve variables from awk sharathkv25 Programming 3 02-16-2007 04:05 AM
How to use session variables in perl ? taqs Programming 1 09-28-2004 07:12 PM
PHP session variables in a database rmanocha Programming 0 07-16-2004 05:18 AM


All times are GMT -5. The time now is 10:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration