I am Unable to insert muliple rows into mysql using Codeigniter for REST API

ساخت وبلاگ

آخرین مطالب

امکانات وب

Vote count: 0

I have created Api for inserting multiple rows into database using codeigniter framework. When i am trying to insert data into database using Postman as data will send through postman only, values are not getting stored into database. I have referred lot of forum but i didn't find solution for my issue. Please help me to get the solution for it.

Here is my code: MyContorller.php

public function addProducts_post(){

        $product_name = $this->post('product_name');
        $quantity_per_pack = $this->post('quantity_per_pack');

        $product_per_pack_unit = $this->post('product_per_pack_unit');

        $data = array();

         for ($i = 0; $i < count($this->post('product_name')); $i++)
        $data[] = array(
            'product_name' => $product_name[$i],
            'quantity_per_pack' => $quantity_per_pack[$i],
            'product_per_pack_unit' => $product_per_pack_unit[$i],
        $insert =  $this->product->add($data);
                'status' => TRUE,
                'message' => 'Products has been added successfully.'
     ], REST_Controller::HTTP_OK);
    else {
        //set the response and exit
            'status' => FALSE,
            'message' => 'Not added'
        ], REST_Controller::HTTP_NOT_FOUND);


public function add($data = array()) {

    $insert = $this->db->insert_batch('product', $data);
        return $this->db->insert_id();
        return false;

asked 29 secs ago
Jayshree patnaik

نویسنده : استخدام کار بازدید : 31 تاريخ : پنجشنبه 13 ارديبهشت 1397 ساعت: 17:04

تبلیغات در اینترنت