Why Mysql Insert Query Returns False

Some days ago I face a problem;  which is my mysql insert query retun false. So I need to dubug the query and wanna to know which problem is here. This help me very much:-

trigger_error(mysql_error());

to debug the query.  I think sometime you need help with that.

$sql = "here is you mysql query";
mysql_query($sql) or trigger_error(mysql_error()." in ".$sql);

Get the Last added ID and Insert it to another Table as a foreign key

Get the last id from the database:-

$this->db->insert_id();

Suppose I have two table ‘product_sale’ and ‘customer_information’. I want to get last id from the ‘product_sale’ table and insert it to ‘customer_information’ table as a foreign key.

public function insertProductsale($data, $data_c) {

$this->db->insert('product_sale', $data);
$sale_id = $this->db->insert_id();
$data_c['sale_id'] = $sale_id;
return $this->db->insert('customer_information', $data_c);
}