It looks like you're new here. If you want to get involved, click one of these buttons!
var dataArr = {
affiliatesArr: Lockr.get("affIDs"),
course_id: "<?=$course_id?>",
transaction_id: "<?=$transaction->id?>"
}
$.ajax({
url: "/transactions/ajax_affiliate_credit",
type: "post",
data: dataArr,
success: function(data) {
console.log("SUCCESS! ");
console.log(data);
},
error: function(data) {
console.log("ERROR: ");
console.log(data);
}
});
<?php
class Transactions extends CI_Controller {
function __construct()
{
parent::__construct();
}
function ajax_affiliate_credit() {
if($this->input->is_ajax_request()) {
$affiliateCredits = $this->input->post();
$this->load->model('transactions_model');
$result = $this->transactions_model->store_affiliate_credits($affiliateCredits);
} else {
return null;
}
}
}
function store_affiliate_credits($affiliateCredits) {
$CI =& get_instance();
$CI->load->model('affiliate_sale_credits_model');
$affiliates = $affiliateCredits['affiliatesArr'];
$course_id = $affiliateCredits['course_id'];
$transaction_id = $affiliateCredits['transaction_id'];
foreach($affiliates as $affiliate) {
$affiliateData = array('transaction_id' => $transaction_id, 'affiliate_id' => $affiliate['id']);
$CI->affiliate_sale_credits_model->save($affiliateData);
$CI->affiliate_sale_credits_model->debug_query();
}
return $affiliateCredits;
}
SUCCESS!
SHOW COLUMNS FROM `affiliate_sale_credits`
CREATE TABLE `affiliate_sale_credits` (
`id` int(11) NOT NULL,
`transaction_id` int(11) NOT NULL,
`affiliate_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `affiliate_sale_credits`
--
ALTER TABLE `affiliate_sale_credits`
ADD PRIMARY KEY (`id`),
ADD KEY `transaction_id` (`transaction_id`),
ADD KEY `affiliate_id` (`affiliate_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `affiliate_sale_credits`
--
ALTER TABLE `affiliate_sale_credits`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
Comments
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Affiliate_sale_credits_model extends Base_module_model { public $foreign_keys = array( 'transaction_id' => 'transactions_model' ); function __construct() { // $this->load->module_model(USER_FOLDER,'site_users_model'); parent::__construct('affiliate_sale_credits'); //table } }
Other info:
* I'm using ion auth - there is a 'user' advanced module
$CI->affiliate_sale_credits_model->save($affiliateData);
Followed by...
$CI->affiliate_sale_credits_model->debug_query();
Result in...
SHOW COLUMNS FROM `affiliate_sale_credits`
I've looked at php and mySQL logs and see no errors.
print_r($CI->affiliate_sale_credits_model->get_errors());
Array ( [transaction_id] => Value needs to be a number for 'transaction id'. [affiliate_id] => Value exceeds required length for 'affiliate id'. ) SHOW COLUMNS FROM `affiliate_sale_credits`
Thanks again. It's now working.