Click to See Complete Forum and Search --> : Can someone pls debug for me. I mean debug not just comment.


terry81
09-08-2004, 04:01 AM
Pls help. Thanks alot.



#!\perl\bin\perl -T

use DBI;
use CGI ":standard";
use strict;


#password retrieved from login.htm passing to variable
$username = param( "username" );
$password = param( "password" );

#configuration to database
$host = "dbi:ODBC:Clients";
$dbh = DBI->connect($host, '','') or die 'Unable to connect to database $dbh->errstr\n';


#check for null
if($username eq "" || $password eq ""){
print ' Please enter your username or password.'
print header, start_html( "Member Login Error" );
print "Please enter your username or password";
print "<FORM METHOD=GET ACTION=\"http://127.0.0.1/login.html\">";
print "<INPUT TYPE=SUBMIT VALUE=\"Back to Login page\">";
print "</FORM>
}

#check for invalid characters
elsif($username =~ /^([\\\(\)\[\{\^\$\*\+\?\.\"\']+)$/ || $password =~ /^([\\\(\)\[\{\^\$\*\+\?\.\"\']+)$/){
print header, start_html( "Member Login Error" );
print "The information you entered contained illegal characters.";
print "<FORM METHOD=GET ACTION=\"http://127.0.0.1/login.html\">";
print "<INPUT TYPE=SUBMIT VALUE=\"Back to Login page\">";
print "</FORM>";
}
elsif(&matchUserPass() == 0){
print header, start_html( "Member Login Error" );
print "Member not found.";
print "<FORM METHOD=GET ACTION=\"http://127.0.0.1/login.html\">";
print "<INPUT TYPE=SUBMIT VALUE=\"Back to Login page\">";
print "<FORM METHOD=GET ACTION=\"http://127.0.0.1/registration.html\">";
print "<INPUT TYPE=SUBMIT VALUE=\"Register Me\">";
print "</FORM>";
}
else
#create session ID
srand($$|time);
$session = int(rand(60000));

#passing session ID to subroutine to create cookie
&createCookie($session);


#passing time and day to variables and passing it to subroutine for record
$time = localtime;
$day = date;
&recordDayTime($time, $day);


#disconnect from database
$dbh->disconnect();
exit;


#HOW TO DIRECT TO THE SHOPPING PAGE ONCE THE MEMBER IS VERIFIED? PLS HELP HERE =P

}


#subroutine for matching username and password with database
sub matchUserPass{
#returns 1 if valid and 0 in not found
my $query = "SELECT COUNT(*) FROM Member WHERE username='$username' AND password='$password'";
return $dbh->selectrow_array($query);
}

#subroutine for recording date and time user login
sub recordDayTime{
my $insert = INSERT INTO Member (Date, Time VisitorIP, VisitorComment)
values ('$time', '$day');
my $update = $dbh->prepare($insert);
$update->execute or die 'Unable to execute SQL command. $dbh->errstr';
}

sub createCookie{
my $this_cookie= cookie(-name=>'Clients', -value=>\$session, -path=>'/', -expire=>'+2h');
}

silent11
09-08-2004, 07:30 AM
humm. debugging would be hard to do without your database. ALso, don't you need some more info to connect to the db, like a username and password?

Did you know that CGI can be use for more than just collecting param()'s? It would pretty up lines that look like this:

print "<FORM METHOD=GET ACTION=\"http://127.0.0.1/login.html\">";


to something like this:

print start_form({action=>'http://127.0.0.1/login.html'});


sorry for the comments :cool: