CUFP
Mr. Muskrat
snippet
<div class="Description">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...</div>
<CODE>
my $sth = $dbh->prepare("UPDATE $table SET upc=$upc WHERE item_id=$item_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);
}
</CODE>