I am a nembie for CGI with Perl, please help me and please correct me wherever I make a mistake.
This is the code. The problem is that after the password is verified and found to be correct, instead of redirecting to the next page, it will send the following message:
Status: 302 Found Location: http:
#!C:\perl\bin\perl.exe use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use DBI; use strict; use DBI; use strict; use warnings; my $q = new CGI; print "Content-Type: text/html\n\n"; if ($q->param("Login")) { my $Password = param('Password'); if (!$Password) { print "Please Enter the Password"; } else { my $dbh = DBI->connect( "dbi:SQLite:DEVICE.db", "", "", { RaiseError => 1, AutoCommit => 1 } ); my $sth = $dbh->prepare("select * from Settings where Password = ?"); $sth->execute($Password); if (my $pass = $sth->fetchrow_hashref) { print redirect(-url => 'http://localhost/cgi-bin/Main.cgi'); } else { print "Invalid Password"; display_form(); } $dbh->disconnect; } } if (($q->param("submit"))) { process_form(); } else { display_form(); } sub process_form { if (validate_form()) { } } sub validate_form { my $User_Password = $q->param("Password"); my $error_message = ""; $error_message .= "Please enter the Password<br/>" if (!$User_Password); if ($error_message) { display_form($error_message, $User_Password); return 0; } } sub display_form { my $error_message = shift; print <<END_HTML; <html> <head><title>Form Validation</title></head> <body> <form method="post"> <input type="hidden" name="submit" value="Submit"> <TABLE align="center" bgcolor=#B0C4DE> <TR> <TD> Enter The Password And Click Login</TD> </TR> <TR></TR> <TR></TR> <TR></TR> <TR></TR> <TR></TR> <TR> <TD><b>PASSWORD</b> : <input type="password" name="Password" size="20" maxlength="15" /></TD> </TR> <TR></TR> <TR></TR> <TR></TR> <TR></TR> <TR></TR> <TR> <TD align="center" colspan="2"> <input type="submit" name="Login" value="Login"> <input type="reset" name="Cancel" value="Cancel"> </TD> </TR> </TABLE </form> </body> </html> END_HTML }
sql perl sql-server-2005 cgi
sonya
source share