Forums / All Other Contributions/Addons / Mass updating of the cift certificates

Mass updating of the cift certificates

Started by ellivir on 14 Sep 2012, 12:51 AM · Views: 562

Results 1 to 1 of 1
14 Sep 2012, 12:51 AM
#1
ellivir avatar

ellivir

Zen Follower

Join Date:
Sep 2005
Posts:
444
Plugin Contributions:
0

Mass updating of the cift certificates

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);
    }

I may be blond but at least I found Zen.