Question: I am trying to insert some values coming from a form as array using the function insert\_batch with CodeIgniter.

This the code in the **controller**:

```
$data_product = array(
'quantity'=> $quantity,
'price'=> $price,
'productID'=> $product_id
);

$this->load->model('product_ordered');
$this->product_ordered->insert_quantity_products($data_product);

```

This is the code in the **model insert\_quantity\_products**

```
public function insert_quantity_products($data){
$this->db->insert_batch('orders', $data);
}

```

And this is the database error

```
Unknown column '0' in 'field list'
INSERT INTO `orders` (`0`, `1`, `2`) VALUES ('3','1','1'),
('358.00','458.00','324.00'), ('1','39','69')

```

The unknown columns should be quantity, price and productID

What I am doing wrong?

Answer: 
in controller

```
$this->load->model('product_ordered');
$this->product_ordered->insert_quantity_products();

```

in model 

1. if you are using single input use this(`$this->db->insert`)

`public function insert_quantity_products()
{
$data_product = array(
'quantity'=> $quantity,
'price'=> $price,
'productID'=> $product_id
);  

$this->db->insert('orders', $data_product);
}`

// Produces: `INSERT INTO orders (quantity, price, productID) VALUES ('$quantity', '$price', '$product_id')`

2. if you are yousing batch insert use this (`$this->db->insert_batch`)

`public function insert_quantity_products()
{
 $data_product = array(
 array(
 'quantity'=> $quantity,
 'price'=> $price,
 'productID'=> $product_id
 );
 array(
 'quantity'=> $quantity2,
 'price'=> $price2,
 'productID'=> $product_id2
 );
 );
$this->db->insert_batch('orders', $data_product);
}`

// Produces: `INSERT INTO orders (quantity, price, productID) VALUES ('$quantity', '$price', '$product_id'),('$quantity2', '$price2', '$product_id2')`
You need to use a 2 Dimensional array for the $data\_product.
This means you controller change $data\_product as below:

`$data_product[] = array('quantity'=> $quantity, 'price'=> $price, 'productID'=> $product_id);`