Welcome Guest, Not a member yet? Register   Sign In
Problem with inserting csv file entries to db
#5

(05-17-2019, 05:53 AM)php_rocs Wrote: @HarrysR,

What does your csv input look like (test data)?  Also, what tools do you use to debug your code? Xdebug? echo statements?  My guest is that there is a problem with your manufacturer-exist method.

Well i feel insanely stupid rn since the solution was really simple and silly.
To begin with, to answer your question, i use "echo" statements.

On the other hand as for the solution here's what was wrong.

In my controller i had this:
Code:
$add_manuf = $this->product_model->add_manufacturer($manufacturer_data);
$insert_data['manufacturer_id'] = $add_manuf['manufacturer_id'];

While the model was like that:
Code:
public function add_manufacturer($data){
$insert = $this->db->insert('manufacturers', $data);
if($insert){
  return $this->db->insert_id();
} else {
  return false;
}
}

So (for people like me who didn't see that coming), while the function returned the last inserted_id of the query, i was trying to access the value as if the sql query returned a row_array.

In two words.... i had to do it like this:
Code:
[BEFORE]
$add_manuf = $this->product_model->add_manufacturer($manufacturer_data);
$insert_data['manufacturer_id'] = $add_manuf['manufacturer_id'];

[AFTER]
$add_manuf = $this->product_model->add_manufacturer($manufacturer_data);
$insert_data['manufacturer_id'] = $add_manuf;


Thank you for your interest in finding the problem guys!

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply


Messages In This Thread
RE: Problem with inserting csv file entries to db - by HarrysR - 05-19-2019, 04:40 PM



Theme © iAndrew 2016 - Forum software by © MyBB