Problem with inserting csv file entries to db |
What i'm facing here has kinda confused me.
I'm trying to insert some entries parsed from csv file into db. I found the csv library, it works and so far so good. I have the following script in controller: "Products/insert", Code: if ($this->csvimport->get_array($file_path)) { And here's my model: Code: public function insert_product($data){ I've also tried batch_insert but i can't check other tables and return the id. If anyone has ever made it, please feel free to suggest a solution on this.. Thanks in advance... //Life motto if (sad() == true) { sad().stop(); develop(); } (05-16-2019, 08:40 PM)php_rocs Wrote: @HarrysR, Yeap that's some very good questions i forgot to answer. So... I have two tables (for now) [products & manufacturers]. What i want to achieve is to upload a csv file and check if the manufacturer exists. If so, then i want to parse the id, and pass it to the "products" table. If not then create the manufacturer entry and get its ID. What i only get is that the column "manufacturer_id" (which is the one i want to get) can not be NULL.. And i don't know why i get this error. As far as i can see the query is right.... //Life motto if (sad() == true) { sad().stop(); develop(); } (05-17-2019, 05:53 AM)php_rocs Wrote: @HarrysR, 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); While the model was like that: Code: public function add_manufacturer($data){ 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] Thank you for your interest in finding the problem guys! //Life motto if (sad() == true) { sad().stop(); develop(); } |
Welcome Guest, Not a member yet? Register Sign In |