Code:

<select id="productKey" name="productKey[]" class="span4" required ></select>
<select id="productKey2" name="productKey[]" class="span4" required ></select>
<select id="productKey3" name="productKey[]" class="span4" required ></select>

I also have my:

  • discount code
  • discount name
  • discount type
  • discount expiration date
  • transaction type
  • and discounted product(productKey)

I am trying to insert the data from the values of those

productKey

In my table, I still want the same code, name, type, expiration date. Here's my code for saving my data. For example:

code : 123456
name : less 50%
type: percentage
expiration date: 2014/08/01 to 2014/08/16
discounted product1 (this is the productKey above) : product1
discounted product2 (this is the productKey above) : product2
discounted product3 (this is the productKey above) : product2

I want to insert all those three through multiple rows, meaning even if I inserted it through multiple rows it would be like this:

code name type expirationdate discounted product
123456 less 50% percentage 2014/08/01 to 2014/08/16 product1
123456 less 50% percentage 2014/08/01 to 2014/08/16 product2
123456 less 50% percentage 2014/08/01 to 2014/08/16 product3

so here are my code:

These are my codes from AdminController.php:

public function savediscountAction(){
    $this->view->disable();
    $get = $this->request;

    $code = $get->get('discountCode');
    $name = $get->get('discountName');
    $desc    = $get->get('discountDesc');
    $type = $get->get('discountType');
    $transaction = $get->get('discountTransaction');
    $exp = $get->get('expiration');
    $expStartDate = $get->get('expStartDate');
    $expEndDate = $get->get('expEndDate');
    $dvalue = $get->get('discountValue');
    $productKey = $get->get('productKey');

    $ph = curl_init();
    $pd = curl_escape($ph, $productKey);

    $url = $this->apiUrl."discount/add?q=(CODE:".urlencode($code).",NAME:".urlencode($name).",DESC:".urlencode($desc).",TYPE:".urlencode($type).",TRANS:".urlencode($transaction).",EXPTYPE:".urlencode($exp).",START:".urlencode($expStartDate).",END:".urlencode($expEndDate).",VALUE:".urlencode($dvalue).",PRODKEY:".urlencode($productKey).")&envelope=false";
    $ch = curl_init($url);
    curl_setopt_array($ch, $this->curlopt);
    echo curl_exec($ch);

    $keys = $this->cache->queryKeys("discount");
    foreach ($keys as $key) {
    $this->cache->delete($key);
    }
    $this->cache->delete("discountData.cache");
    }

and these are my codes from DiscountController.php

public function addDiscount(){

    foreach ($this->searchFields as $field => $value) { 
    if($field == 'NAME'){
    $discountName = $value;
    }else if($field == 'CODE'){ 
    $discountCode = $value;
    } else if($field == 'DESC'){
    $discountDesc = $value;
    }else if($field == 'TYPE'){
    $discountType = $value;
    }else if($field == 'TRANS'){
    $discountTransaction = $value;
    }else if($field == 'EXPTYPE'){
    $expiration = $value;
    }else if($field == 'START'){
    $expStartDate = $value;
    }else if($field == 'END'){
    $expEndDate = $value;
    }else if($field == 'VALUE'){
    $discountValue = $value;
    }else if($field == 'PRODKEY'){
    if($value == null || $value == ""){
    $productKey = "";
    }else{
    $productKey = $value;
    }
    }
    }

    $ph = curl_init();
    $pd = curl_unescape($ph, $discountedProduct);
    $pk = curl_unescape($ph, $productKey);

    $discount = new VlDiscount();

    $discount->discountName = $discountName;
    $discount->discountCode = $discountCode;
    $discount->discountDesc = $discountDesc;
    $discount->discountType = $discountType;
    $discount->discountTransaction = $discountTransaction;
    $discount->expiration = $expiration;
    $discount->expStartDate = $expStartDate;
    $discount->expEndDate = $expEndDate;
    $discount->discountValue = $discountValue;/* 
    $discount->discountedProduct = mysql_escape_string($pd); */
    $discount->productKey = mysql_escape_string($pk);
    $discount->app_id = $this->session->get('appId');

    $data = array(); 
    if($discount->create() == false){
    $devMessage = array();
    foreach ($discount->getMessages() as $key){
    $devMessage[] = $key->getMessage();
    } 
    return $this->respond(array( 
    'userMessage' => 'Failed',
    'devMessage' => $devMessage, 
    'more' => 'Failed to create. One or more fields failed on validation.'
    ));
    } else { 
    return $this->respond(array('userMessage' => 'OK')); 
    }
    }

and these are my codes from discounts.js

    function savePage(){
    if(!$('input,textarea').jqBootstrapValidation("hasErrors")){
    if(saveType == 's'){
    url = baseUrl+'/admin/savediscount';
    }else{
    url = baseUrl+'/admin/updatediscount';
    }

    $.ajax({
    type    : 'GET',
    async   : false, 
    data    : {
    key : key,
    discountCode :$('#discountCode').val(),
    discountName : $('#discountName').val(),
    discountDesc : $('#discountDesc').val(),
    discountType : $('#discountType').val(),
    expiration : $('#expiration').val(),
    expStartDate : $('#expStartDate').val(),
    expEndDate : $('#expEndDate').val(),
    discountValue : $('#discountValue').val(),
    discountTransaction : $('#discountTransaction').val(),
    productKey   : $('#productKey').val()
    },
    url  : url,
    error: function(req,error){ 
    notify('e',req.statusText);
    },
    dataType: 'json',
    cache: false,
    success : function(msg){ 
    console.log(msg);
    if(msg[0].userMessage =='OK'){ 
    var discountName = $('#discountName').val();
    closePage(); 
    if(saveType == 's'){
    notify('s',discountName+' information has been saved.');
    }else{
    notify('s',discountName+' information has been modified.');
    }
    }else{
    var str = '';
    $.each(msg[0].devMessage,function(e,i){
    str += i +',';
    });
    notify('e',str.substring(0,str.length - 1));
    } 
    }
    });
    }else{
    var errors = $('input,textarea').jqBootstrapValidation("collectErrors");
    $('#pageInput').submit();
    } }