Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    posting data on different table

    hey everyone! i am trying to insert values on diffrerent tables with these codes i am using phalcon as my framework :
    Code:
    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 = urldecode($value);
    			}else if($field == 'TRANS'){
    				$discountTransaction = urldecode($value);
    			}else if($field == 'EXPTYPE'){
    				$expiration = urldecode($value);
    			}else if($field == 'START'){
    				$expStartDate = $value;
    			}else if($field == 'END'){
    				$expEndDate = $value;
    			}else if($field == 'VALUE'){
    				$discountValue = $value;
    			} else if($field == 'PRODKEY'){
    				$productId = $value;
    			}
    		}
    	     
    		$ph = curl_init();
    		$pd = curl_unescape($ph, $discountedProduct);
    		$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->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 if ($discountTransaction == 'p'){
    				$ph = curl_init();
    				$pk = curl_unescape($ph, $productId);				
     				$exp = explode('/',$pk);
    				$prod = 0;
    				foreach ($exp as $item){
    					$sql = VlProduct::query()
    								->columns('autokey')
    								->where('autokey = ?1')
    								->andWhere('app_id = ?2')
    								->bind(array(1=>$item,2=>$this->session->get('appId')))
    								->execute();
    					
    					if($sql->count() == 0){
    							$productDiscount = new VlDiscountProduct();
    							$productDiscount->discountId 	= $discount->autokey;
    							$productDiscount->productId 	= (int)trim($item);
     							$productDiscount->app_id 		= $this->session->get('appId');
    							$productDiscount->create();
    
    						$data = array();
    						if($productDiscount->create() == false){
    							$prod++;
    							$devMessage = array();
    							foreach ($productDiscount->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.'
    							));
     					}
     				}
    			}
    			return $this->respond(array('userMessage' => 'OK')); 
    	}
    }
    my admin controller could already receive all the data sent from my discount.js. my problem here is that my function above is just insert the values in my VlDiscount but not in my VlDiscountProduct.

    i already have 3 tables
    vl_discount, vl_product and vl_discount_product

    from my vl_discount_product i got these fields
    autokey in PRIMARYKEY
    discountId int FOREIGNKEY reference vl_discount.autokey
    productId int FOREIGNKEY refernce vl_product.autokey


    it only saves in my vl_discount table but not in my vl_discount_product :'< thank you in advance!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    So what debugging have you done???

    And how are we supposed to guess what your discount.js code is doing?

    If it doesn't send the info for the product, it wouldn't be surprising if no products are processed.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •