in reply to $dbh->errstr;

Well, your database handle ($dbh) returns a statement handle which goes out of scope pretty soon.. You might want to read about the DBI..

-octo