http://qs321.pair.com?node_id=162350

Sometimes you have some data to update but someone slips in some stuff thats not in the database yet. Well, you could explicitly check if it's there using a SELECT or you could do something like this...
my $sth = $dbh->prepare("UPDATE $table SET upc=$upc WHERE item_id=$ite +m_id;"); die "DBH Error:" . $dbh->errstr . "\n" if (!$sth); if (!$sth->execute) { # Oops! $item_id doesn't exist in $table so add it. my $sth = $dbh->prepare("INSERT INTO $table (item_id, upc) VALUES( +$item_id, $upc);"); die "DBH Error:" . $dbh->errstr . "\n" if (!$sth); die "STH Error:" . $sth->errstr . "\n" if (!$sth->execute); }