...

View Full Version : Software error: with Perl/CGI



dark0s
01-17-2010, 01:28 PM
I have my home.html pahe in /var/www directory and login.cgi in /usr/lib/cgi-bin directory with 0755 permissions. My form in home.html is:


<form action="/cgi-bin/login.cgi" method="get" class="form-font">
<label>Already you registered?</label><br/><hr/><br/>
<fieldset><br/>
<legend>Insert your account</legend>
Email: <input type="text" name="email"/><br/><br/>
Password: <input type="text" name="password"/><br/><br/>
<input type="submit" value="Log In" /><br/><br/>
</fieldset>
</form>
My /usr/lib/cgi-bin/login.cgi script is:


#!/usr/bin/perl

use feature say;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;

my $cgi = CGI->new();

$email = $cgi->param('email');
$password = $cgi->param('password');

my $db = 'mydb';
my $user = 'myuser';
my $pw = 'passwd';

my $dbh = DBI->connect("DBI:mysql:$db",$user,$pw) or
die "Non posso connetermi al database $db: $DBI::errstr\n" unless (defined $dbh);

$query = qq{SELECT mionickname, miamail FROM clients WHERE email='miamail';};

my $sth = $dbh->prepare($query) or die "$dbh->errstr\n";
my $rc = $sth->execute or die "$dbh->errstr\n";

$dbh->disconnect;

say "<html>";
say "<h1>Hi $nickname</h1>";
say "</html>";
When I log in home.html, the output is:


Software error:

DBI::db=HASH(0x282fff0)->errstr

For help, please send mail to the webmaster (webmaster@localhost), giving this error message and the time and date of the error.
If I modify following instructions with comments in /usr/lib/cgi-bin/login.cgi:


my $sth = $dbh->prepare($query); #or die "$dbh->errstr\n";
my $rc = $sth->execute; #or die "$dbh->errstr\n";
then output is:


500 Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Apache/2.2.12 (Ubuntu) Server at localhost Port 80
What is the problem?

oesxyl
01-17-2010, 01:37 PM
I have my home.html pahe in /var/www directory and login.cgi in /usr/lib/cgi-bin directory with 0755 permissions. My form in home.html is:

My /usr/lib/cgi-bin/login.cgi script is:

When I log in home.html, the output is:

If I modify following instructions with comments in /usr/lib/cgi-bin/login.cgi:

then output is:

What is the problem?
don't use quote when you post code please.
replace:


say "<html>";
say "<h1>Hi $nickname</h1>";
say "</html>";

with:


print $cgi->header,
$cgi->start_html,
qq(<h1>$nickname</h1>),
$cgi->end_html;


best regards

dark0s
01-17-2010, 02:13 PM
There is not output, after click login button the firefox page is white and url in my host is:

http://localhost/cgi-bin/login.cgi?email=mioindirizzo&password=miapasword

Peraphs there is an error in login.cgi script.
Instead if write:


my $sth = $dbh->prepare($query) or die "$dbh->errstr\n";
my $rc = $sth->execute or die "$dbh->errstr\n";

then output always is:
]Software error:

DBI::db=HASH(0xc401b8)->errstr

For help, please send mail to the webmaster (webmaster@localhost), giving this error message and the time and date of the error.

FishMonger
01-17-2010, 04:09 PM
You're missing 2 very important pragmas which should be in every Perl script you write.

use strict;
use warnings;

Take this off of your die statement.

unless (defined $dbh)

$dbh->errstr is a method (subroutine) call which doesn't work inside of a double quoted string.

So, change:

or die "$dbh->errstr\n";
To:

or die $dbh->errstr;

dark0s
01-17-2010, 05:35 PM
The problem was for a syntax error in SQL and DBI.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum