- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- problem with cgi and html
Operating System - HP-UX
1754376
Members
3292
Online
108813
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2009 07:23 PM
08-24-2009 07:23 PM
problem with cgi and html
I am trying to make one small application using
CGI::Application and HTML::Template
for students which is basically log in using username and password, if entered wrong displays the error page, in success it should show the status of student but I am having some problems and dont know what did i do wrong.
Anyone can help me out please what is wrong with my code.
I am going to paste everything i have done.
I think html::template representation also not good.
PACKAGE
Test1.pm
package test1;
use strict;
use warnings;
use base 'CGI::Application';
sub setup{
my $self = shift;
$self->start_mode('login');
$self->mode_param('newState');
$self->run_modes(['login', 'authentication', â displayâ ]);
}
CGI PAGE
Test1.cgi
#!/usr/bin/perl
use strict;
use DBI;
$database = â Oracleâ ;
$db_server = â ECAT01Bâ ;
$user = â ECSTWEBâ ;
$password = â ECSTWEBâ ;
use test1;
my $test1= test1->new();
$test1->run();
sub login{
my $self = shift;
my $HTMLPage = $self->load_tmpl('test1.tmpl');
$HTMLPage->param('showSection_login' => 1);
return $HTMLPage->output;
}
sub authentication{
my $self = shift;
my $query = $self->query();
my $User_Name = $query->param('User_Name');
my $Password = $query->param('Password');
my $dbh = DBI->connect (â DBI: $database: $db_server ','$user ','$password ', { RaiseError => 1, AutoCommit => 0 } ) || die "Database connection not made: $DBI::errstr";
my $HTMLPage = $self->load_tmpl('test1.tmpl');
my $SEL = â select User_Name, Password from User_Info where User_Name = $User_Name and Password = $Passwordâ ;
my $sth = $dbh->prepare($SEL) or die â Couldnâ t prepare the query: $dbh->errstrâ ;
my $rv = $sth ->execute or die â Couldnâ t execute query: $dbh -> errstrâ ;
while (($SQLUser_Name, $SQLPassword) = $execute -> fetchrow_hashref())
{
if (($password eq â $SQLPasswordâ ) and ( $User_Name eq â $SQLUser_Nameâ ))
{
$HTMLPage->param('showSection_welcomePage' => 1);
$HTMLPage->param('user' => $User_Name);
} else
{
$HTMLPage->param('showSection_loginFailed' => 1);
}
return $HTMLPage->output;
}
sub display{
my $self = shift;
my $query = $self->query();
my $dbh = DBI->connect (â DBI: $database: $db_server ','$user ','$password ', { RaiseError => 1, AutoCommit => 0 } ) || die "Database connection not made: $DBI::errstr";
my $HTMLPage = $self->load_tmpl('test1.tmpl');
my $SEL = â SELECT First_Name, Last_Name, Address, User_Name, Status, University FROM User_Info a, Admission_Code b, Univ_Code c, User_Admission_Status WHERE a.User_Name=d.U_Name and b.Adm_Code=d.Admission_Code and c.Univ_Code=d.Univ_Code and a.User_Name='form.User_Name'â ;
my $sth = $dbh-> prepare($SEL) or die â Couldnâ t prepare the query: $dbh-> errstrâ ;
my $rv = $sth -> execute or die â Couldnâ t execute query: $dbh -> errstrâ ;
while (@row= $execute -> fetchrow_hashref())
$HTMLPage-> param('showSection_display' => 1);
$HTMLPage-> param(â First_Nameâ => $First_Name);
$HTMLPage-> param(â Last_Nameâ => $Last_Name);
$HTMLPage-> param(â Addressâ => $Address);
$HTMLPage->param(â User_Nameâ => $User_Name);
$HTMLPage->param(â Statusâ => $Status);
$HTMLPage->param(â Universityâ => $University);
return $HTMLPage->output;
}
HTML Template File
Test1.tmpl
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Perl Login
Login succeeded: Welcome
continues in attached text file----
CGI::Application and HTML::Template
for students which is basically log in using username and password, if entered wrong displays the error page, in success it should show the status of student but I am having some problems and dont know what did i do wrong.
Anyone can help me out please what is wrong with my code.
I am going to paste everything i have done.
I think html::template representation also not good.
PACKAGE
Test1.pm
package test1;
use strict;
use warnings;
use base 'CGI::Application';
sub setup{
my $self = shift;
$self->start_mode('login');
$self->mode_param('newState');
$self->run_modes(['login', 'authentication', â displayâ ]);
}
CGI PAGE
Test1.cgi
#!/usr/bin/perl
use strict;
use DBI;
$database = â Oracleâ ;
$db_server = â ECAT01Bâ ;
$user = â ECSTWEBâ ;
$password = â ECSTWEBâ ;
use test1;
my $test1= test1->new();
$test1->run();
sub login{
my $self = shift;
my $HTMLPage = $self->load_tmpl('test1.tmpl');
$HTMLPage->param('showSection_login' => 1);
return $HTMLPage->output;
}
sub authentication{
my $self = shift;
my $query = $self->query();
my $User_Name = $query->param('User_Name');
my $Password = $query->param('Password');
my $dbh = DBI->connect (â DBI: $database: $db_server ','$user ','$password ', { RaiseError => 1, AutoCommit => 0 } ) || die "Database connection not made: $DBI::errstr";
my $HTMLPage = $self->load_tmpl('test1.tmpl');
my $SEL = â select User_Name, Password from User_Info where User_Name = $User_Name and Password = $Passwordâ ;
my $sth = $dbh->prepare($SEL) or die â Couldnâ t prepare the query: $dbh->errstrâ ;
my $rv = $sth ->execute or die â Couldnâ t execute query: $dbh -> errstrâ ;
while (($SQLUser_Name, $SQLPassword) = $execute -> fetchrow_hashref())
{
if (($password eq â $SQLPasswordâ ) and ( $User_Name eq â $SQLUser_Nameâ ))
{
$HTMLPage->param('showSection_welcomePage' => 1);
$HTMLPage->param('user' => $User_Name);
} else
{
$HTMLPage->param('showSection_loginFailed' => 1);
}
return $HTMLPage->output;
}
sub display{
my $self = shift;
my $query = $self->query();
my $dbh = DBI->connect (â DBI: $database: $db_server ','$user ','$password ', { RaiseError => 1, AutoCommit => 0 } ) || die "Database connection not made: $DBI::errstr";
my $HTMLPage = $self->load_tmpl('test1.tmpl');
my $SEL = â SELECT First_Name, Last_Name, Address, User_Name, Status, University FROM User_Info a, Admission_Code b, Univ_Code c, User_Admission_Status WHERE a.User_Name=d.U_Name and b.Adm_Code=d.Admission_Code and c.Univ_Code=d.Univ_Code and a.User_Name='form.User_Name'â ;
my $sth = $dbh-> prepare($SEL) or die â Couldnâ t prepare the query: $dbh-> errstrâ ;
my $rv = $sth -> execute or die â Couldnâ t execute query: $dbh -> errstrâ ;
while (@row= $execute -> fetchrow_hashref())
$HTMLPage-> param('showSection_display' => 1);
$HTMLPage-> param(â First_Nameâ => $First_Name);
$HTMLPage-> param(â Last_Nameâ => $Last_Name);
$HTMLPage-> param(â Addressâ => $Address);
$HTMLPage->param(â User_Nameâ => $User_Name);
$HTMLPage->param(â Statusâ => $Status);
$HTMLPage->param(â Universityâ => $University);
return $HTMLPage->output;
}
HTML Template File
Test1.tmpl
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Login succeeded: Welcome !
Login failure: Invalid username or password
- Tags:
- Perl
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP