I am trying to use one of stores hooks to insert data into the database when displaying the success page after paying online for an order and I get the following error:
Error Number: 1096
No tables used
SELECT *
This is the function I am calling on the store_order_complete_end
hook from store:
public function store_order_complete_end($member_id) { // hook
try {
// generate coupon code
$coupon_code = 'FLK-' . mt_rand(100000000, 999999999);
// generate coupon code until code is unique
while ($this->check_coupon($coupon_code)) {
$coupon_code = 'FLK-' . mt_rand(100000000, 999999999);
}
//-----------------------------------------------------
// -- inserting into table exp_channel_titles --
// retrieving the next available primary key value
$entry_id = ee()->db->insert_id();
// array containing the data that will be inserted into the database
$titles = array(
'entry_id' => $entry_id,
'site_id' => 1,
'channel_id' => 8,
'author_id' => $member_id,
'ip_address' => null,
'title' => $coupon_code,
'url_title' => strtolower($coupon_code),
'status' => 'open',
'entry_date' => strtotime('now')
);
// insert coupon into table exp_channel_titles
ee()->db->insert('exp_channel_titles', $titles);
//-----------------------------------------------------
//-----------------------------------------------------
// -- inserting into table exp_channel_data --
// array containing the data that will be inserted into the database
$data = array(
'entry_id' => $entry_id,
'site_id' => 1,
'channel_id' => 8,
//'field_id_44' => $assoc_product,
'field_id_45' => $member_id
);
// insert coupon into table exp_channel_data
ee()->db->insert('exp_channel_data', $data);
//-----------------------------------------------------
/// setting the return value if successful
$this->returndata = true;
// returning the data
return $this->returndata;
} catch (Exception $err) {
// returning the exception if any
return $err;
}
}
Referenced function:
public function check_coupon($coupon_code) {
try {
// selecting the coupon code field
ee()->db->select('title');
// building the conditions
$query = ee()->db->get_where('exp_channel_titles', array('title' => $coupon_code, 'channel_id' => 8));
// retrieving the data into a variable
$result = $this->EE->db->get()->result_array();
// return true if the coupon exist
if (!empty($result)) {
return true;
}
// return false if the coupon does not exist
return false;
} catch (Exception $err) {
// returning the exception if any
return $err;
}
}