CodeIgniter Forums
Insert data into database from notepad file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Insert data into database from notepad file (/thread-50750.html)



Insert data into database from notepad file - El Forum - 04-06-2012

[eluser]Farzand[/eluser]
i am working on amazon ECS api . so i upload asin from notepad file and insert asin into database then asin search product from amazon. i try to insert asin into database but its failed.here is my code

$data = array(
'category_id'=> $this->input->post('state'),
'title'=> $this->input->post('title'),
'date_created' => date('Y-m-d H:iConfused'),
'date_modified' => date('Y-m-d H:iConfused')
);
$this->db->insert($this->product_list,$data);
$id = $this->db->insert_id();
$asins = array();
$images = $this->do_upload("productasins");
if($images['file_name'] !="")
{
$images = $images['file_name'];
} else {
$images = 'no';
}
if(!empty($images)){
$path = './public/files/'.$images;
$asin_file = file_get_contents($path);

$str_products = $this->input->post('productasins') . ' ' . $asin_file;
}else{
$str_products = $this->input->post('productasins');
}
$products = preg_split("/[\s,]+/", $str_products);
foreach ($products as $product_asin) {
$product_asin = trim($product_asin);
if ($product_asin != "") {
$this->db->where( array('asin' => $product_asin));
$product = $this->db->get('product');
if ($product == null) {
$data = array(
'asin' => $product_asin,
'product_list_id' => $id
);
print_r($this->db->insert('product',$data));
}
}
}