hi monks, i started learning perl not to long ago, and IMHO id say im doing pretty good, learning at a good rate, but unfortunately im not creative enough to just make up programs to write to practice, so im forced to try to make any task that i, or anyone in my house does, a perl script

anyway, my wife owes her dad some money, and she asked me to load MS Word on a computer so she could keep track of the balance, the amount she just paid him, and have a paper copy. Of course the first thing i did was go and download mysql and install DBI, now this is my first time trying to write anything accessing a database, mysql or otherwise, so if you see errors other than what im asking about, please point them out, like i said this is purely for learning reasons, i know alot of things (like mysql and digest_md5) are not really necessary for what im doing, but im trying to get myself familiar with anything i can

so i have a simple HTML page that just has username and password field and a submit button, from there it comes to the code below which is where im having the problem. when i leave a field blank (either one) it does what it should, when i put an invalid username it does what it should, but when i put a valid username, and invalid password it gives me the invalid username error error message, in the error log it says
[Fri Aug 16 21:49:25 2002] [error] [client 12 +7.0.0.1] [Fri Aug 16 21:49:25 2002] amysloan.cgi: Data +base handle destroyed without explicit disconnect., referer: http://l +ocalhost/cgi-bin/amysloan.cgi [Fri Aug 16 21:49:31 2002] [error] [client 12 +7.0.0.1] [Fri Aug 16 21:49:31 2002] amysloan.cgi: Use +of uninitialized value in string ne at C:/Program Files/Apache Group/ +Apache2/cgi-bin/amysloan.cgi line 32., referer: http://localhost/cgi- +bin/amysloan.cgi
i dont know for sure if that helps or not, i was thinking that the uninitialized error might mean something about the problem im having, now if i put in the correct username and password, it prints the loan amount, just like i want it to, the only time i have a problem is if i put a valid username and invalid password..well here's my code:
#!/Perl/bin/perl -w use Digest::MD5 qw/md5_base64/; use CGI::Carp qw/fatalsToBrowser/; use CGI qw/:standard/; use DBI; use strict; print "Content-type:text/html\n\n"; my %info; my $driver = "mysql"; my $database = "amy"; my $dsn = "DBI:$driver:database=$database;host=localhost"; my $dbh = DBI->connect($dsn) or die "Couldnt connect: $DBI::errstr\n"; my $username = param('username'); my $password = md5_base64(param('password')) if param('password'); if(!$username){ relogin("Enter your username"); }elsif(!$password){ relogin("Enter your password"); } my $sth = $dbh->prepare("SELECT * FROM info WHERE pword='$password'"); $sth->execute() or die "Couldnt do it: $!\n"; while(my $ref = $sth->fetchrow_hashref){ %info = %{$ref}; } $sth->finish(); $dbh->disconnect(); if($username ne $info{'uname'}){ relogin("Invalid Username"); } if($password ne $info{'pword'}){ relogin("Invalid Password"); } print $info{'loan'}; sub relogin{ my $msg = shift; print <<HtmlCode; <html> <head> <title>Login</title> </head> <body> <center> <form action="/cgi-bin/amysloan.cgi" method="post"> <table border="0"> <tr> <td colspan="2"><center>$msg</center></td> </tr> <tr> <td>Login:</td> <td><input name="username" size="10" value="$username"></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" size="10"></td> </tr> <tr> <td colspan="2"><center><input type="submit" value="login"></center> +</td> </tr> </table> </form> </center> </body> </html> HtmlCode exit; }

In reply to Accessing information pulled from mysql by blaze

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.