my $product_id; my $sth = $dbh->prepare("SELECT products_id, products_quantity, products_weight, products_price, vendors_id FROM products WHERE products.products_model = ".$dbh->quote($data->{'manufacturer_model'})); $sth->execute(); if (my $ref = $sth->fetchrow_hashref()) { $product_id = $ref->{'products_id'}; my $product_price = $ref->{'products_price'}; my $product_quantity = $ref->{'products_quantity'}; my $product_weight = $ref->{'products_weight'}; my $sths = $dbh->prepare("SELECT products_id FROM specials WHERE specials.products_id = ".$product_id); $sths->execute(); # don't update if product is in specials unless (my $id = ($sths->fetchrow_array)[0]) { if ($ref->{'vendors_id'} == 1) { $dbh->do("UPDATE products SET products.vendors_id = ".$data->{'vendor_id'}." WHERE products.products_id = ".$product_id); } # update when price/stock conditions met if (($data->{'price'} <= $product_price && $data->{'quantity'} > 0). || ($product_quantity == 0 && $data->{'quantity'} > 0)) { $dbh->do("UPDATE products SET products.products_price = ".$data->{'price'}.", products.products_quantity = ".$data->{'quantity'}.", products.vendors_id = ".$data->{'vendor_id'}.", products.products_availability = ".$data->{'availability'}." WHERE products.products_id = ".$product_id); } }