Operating System - HP-UX
1754376 Members
3292 Online
108813 Solutions
New Discussion

problem with cgi and html

 
pareshan
Regular Advisor

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




user:


password:






Login succeeded: Welcome !


Login failure: Invalid username or password




continues in attached text file----

I couldnt fit all the codes here so I am going to attach in a text file

Its more like prototype so any suggestion how can i make it effective and whats wrong I have done in the entire problem will be appreciated
I will really appreciate any help.
thanks in advance