Every database has its own way of getting a sequence number or
id number from the last insert, so you are stuck with
whatever your database offers in that regard. You might
simplify the whole thing with something like this,
though, using eval to eliminate the other
conditionals (and also checks the status of getting
the last id inserted, which you are not doing):
$dbh->{RaiseError}=1;
eval {
insert...
get last id...
insert...
};
if ($@) {
insert failed...
}
insert succeeded...