Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Software error: with Perl/CGI

    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?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by dark0s View Post
    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:
    Code:
    say "<html>";
    say "<h1>Hi $nickname</h1>";
    say "</html>";
    with:
    Code:
    print $cgi->header,
      $cgi->start_html,
      qq(<h1>$nickname</h1>),
      $cgi->end_html;
    best regards

  • #3
    New Coder
    Join Date
    Jan 2010
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?e...ord=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.
    Last edited by dark0s; 01-17-2010 at 03:40 PM.

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,904
    Thanks
    2
    Thanked 164 Times in 159 Posts
    You're missing 2 very important pragmas which should be in every Perl script you write.
    Code:
    use strict;
    use warnings;
    Take this off of your die statement.
    Code:
    unless (defined $dbh)
    $dbh->errstr is a method (subroutine) call which doesn't work inside of a double quoted string.

    So, change:
    Code:
    or die "$dbh->errstr\n";
    To:
    Code:
    or die $dbh->errstr;

  • #5
    New Coder
    Join Date
    Jan 2010
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Software error: with Perl/CGI [SOLVED]

    The problem was for a syntax error in SQL and DBI.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •