I am new to stackoverflow. So, forgive me for anything wrong. I am not so expert in programming area.
I am trying to build an small application using Codeigniter. I do not not how to pass dynamic same input field value using jQuery to Codeigniter controller to model. I am using this jQuery plugin to make dynamic input field.
For test purpose, I have pasted same html input code more than 3times.
Error:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0, 1, 2) VALUES ('','',''), ('','',''), ('','',''), ('','',''), ('','',''), ('',' at line 1
INSERT INTO
products
(0, 1, 2) VALUES ('','',''), ('','',''), ('','',''), ('','',''), ('','',''), ('','',''), ('','','')Filename: C:/xampp/htdocs/store_management/system/database/DB_driver.php
Line Number: 691
My code:
function add_product($params)
{
$this->db->insert_batch('products',$params);
return $this->db->insert_id();
}
function add()
{
if(isset($_POST) && count($_POST) > 0)
{
$params = array(
'code_number' => $this->input->post('code_number'),
'product_name' => $this->input->post('product_name'),
'brand_name' => $this->input->post('brand_name'),
'product_category' => $this->input->post('product_category'),
'cost_price' => $this->input->post('cost_price'),
'selling_price' => $this->input->post('selling_price'),
'initial_stock' => $this->input->post('initial_stock'),
);
$product_id = $this->Product_model->add_product($params);
redirect('product/index');
}
else
{
$this->load->view('product/add');
}
}
<?php echo form_open( 'product/add',array( "class"=>"form-horizontal","id"=>"dynamic")); ?>
<table>
<tbody id="itemlist">
<tr>
<td>
<input class="form-control input-sm text-right" name="code_number[]" value="<?php echo $this->input->post('code_number'); ?>">
</td>
<td>
<input class="form-control input-sm" name="product_name[]" value="<?php echo $this->input->post('product_name'); ?>">
</td>
<td>
<input class="form-control input-sm" name="brand_name[]" value="<?php echo $this->input->post('brand_name'); ?>">
</td>
<td>
<input class="form-control input-sm" name="product_category[]" value="<?php echo $this->input->post('product_category'); ?>">
</td>
<td>
<input class="form-control input-sm" name="cost_price[]" value="<?php echo $this->input->post('cost_price'); ?>">
</td>
<td>
<input class="form-control input-sm" name="selling_price[]" value="<?php echo $this->input->post('selling_price'); ?>">
</td>
<td>
<input class="form-control input-sm" name="initial_stock[]" value="<?php echo $this->input->post('initial_stock'); ?>">
</td>
<td class="text-center">
<button class="btn-remove btn btn-sm btn-danger"><i class="fa fa-times fa-fw"></i>
</button>
</td>
</tr><tr>
<td>
<input class="form-control input-sm text-right" name="code_number[]" value="<?php echo $this->input->post('code_number'); ?>">
</td>
<td>
<input class="form-control input-sm" name="product_name[]" value="<?php echo $this->input->post('product_name'); ?>">
</td>
<td>
<input class="form-control input-sm" name="brand_name[]" value="<?php echo $this->input->post('brand_name'); ?>">
</td>
<td>
<input class="form-control input-sm" name="product_category[]" value="<?php echo $this->input->post('product_category'); ?>">
</td>
<td>
<input class="form-control input-sm" name="cost_price[]" value="<?php echo $this->input->post('cost_price'); ?>">
</td>
<td>
<input class="form-control input-sm" name="selling_price[]" value="<?php echo $this->input->post('selling_price'); ?>">
</td>
<td>
<input class="form-control input-sm" name="initial_stock[]" value="<?php echo $this->input->post('initial_stock'); ?>">
</td>
<td class="text-center">
<button class="btn-remove btn btn-sm btn-danger"><i class="fa fa-times fa-fw"></i>
</button>
</td>
</tr><tr>
<td>
<input class="form-control input-sm text-right" name="code_number[]" value="<?php echo $this->input->post('code_number'); ?>">
</td>
<td>
<input class="form-control input-sm" name="product_name[]" value="<?php echo $this->input->post('product_name'); ?>">
</td>
<td>
<input class="form-control input-sm" name="brand_name[]" value="<?php echo $this->input->post('brand_name'); ?>">
</td>
<td>
<input class="form-control input-sm" name="product_category[]" value="<?php echo $this->input->post('product_category'); ?>">
</td>
<td>
<input class="form-control input-sm" name="cost_price[]" value="<?php echo $this->input->post('cost_price'); ?>">
</td>
<td>
<input class="form-control input-sm" name="selling_price[]" value="<?php echo $this->input->post('selling_price'); ?>">
</td>
<td>
<input class="form-control input-sm" name="initial_stock[]" value="<?php echo $this->input->post('initial_stock'); ?>">
</td>
<td class="text-center">
<button class="btn-remove btn btn-sm btn-danger"><i class="fa fa-times fa-fw"></i>
</button>
</td>
</tr><tr>
<td>
<input class="form-control input-sm text-right" name="code_number[]" value="<?php echo $this->input->post('code_number'); ?>">
</td>
<td>
<input class="form-control input-sm" name="product_name[]" value="<?php echo $this->input->post('product_name'); ?>">
</td>
<td>
<input class="form-control input-sm" name="brand_name[]" value="<?php echo $this->input->post('brand_name'); ?>">
</td>
<td>
<input class="form-control input-sm" name="product_category[]" value="<?php echo $this->input->post('product_category'); ?>">
</td>
<td>
<input class="form-control input-sm" name="cost_price[]" value="<?php echo $this->input->post('cost_price'); ?>">
</td>
<td>
<input class="form-control input-sm" name="selling_price[]" value="<?php echo $this->input->post('selling_price'); ?>">
</td>
<td>
<input class="form-control input-sm" name="initial_stock[]" value="<?php echo $this->input->post('initial_stock'); ?>">
</td>
<td class="text-center">
<button class="btn-remove btn btn-sm btn-danger"><i class="fa fa-times fa-fw"></i>
</button>
</td>
</tr>
</tbody>
</table>