Hi,
trying to make mass updating for gift certificates and I get the csv file loaded but handling the data is not working for inserting the amounts and checking if the customer_id already exists, then can UPDATE the saldo, in other case need to INSERT a new customer_id in the table and the amount.

Code is like this below. Anybody see any clear mistakes in the idea of it?

function insert_customer() {
global $db, $messageStack;

$customer_id = zen_db_prepare_input($_POST['customer_id']);
$amount = zen_db_prepare_input($_POST['amount']);

// Check if the customer_id exists
$customer_exists = $db->Execute("select customer_id from " .
TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . $customer_id . "'");

// Check the amount of gv
$customer_gv = $db->Execute("select amount
from " . TABLE_COUPON_GV_CUSTOMER . "
where customer_id = '" . $customer_id . "'");

if ($customer_exists->RecordCount() != 0) {
$new_gv_amount = $customer_gv->fields['amount'] + $amount;

$sql = "update " . TABLE_COUPON_GV_CUSTOMER . "
set amount = '" . $new_gv_amount . "'
where customer_id = '" . $customer_id . "'";

$db->Execute($sql);

} else {
$sql = "insert into " . TABLE_COUPON_GV_CUSTOMER . " (amount) values ('" . $customer_gv->fields['amount'] . "')";

$db->Execute($sql);
}