in reply to DBI Question

You're mixing up database handle (usually $dbh) and statement handle (usally $sth) in this line:
$dbh = $dbh->prepare(...)

That will place a statement handle (return value from $dbh->prepare) in a variable that you think contains a database handle. Another $dbh->prepare call goes BOOM.

So don't do that, use separate variables for separate things. There are working examples in the DBI docs.