Q:

How To Insert Data Using Multiple Input With Same Name in codeigniter

I'm using JavaScript would produce the following entries
<input type="hidden" name="my_img[]" value="dad6e52b274690409835.jpg">
<input type="hidden" name="my_img[]" value="252529b6e21f872c7675.jpg">
<input type="hidden" name="my_img[]" value="3cce4128c366216fsfaf.jpg">
<input type="hidden" name="my_img[]" value="48697e8516caa3cc15d4.jpg">

But I've had trouble inserting them in the database
my controllers :
   $dd=$this->input->post('my_img');
   for($i=0;$i<count($dd);$i++)
   {
   $img_box[$i] = array ('img_url' => $dd[$i]);
   }
   $this->posts_model->add_new_ads_img($img_box);

my model :
public function add_new_ads_img($img_box)
{
    $q = $this->db->insert('advertise_gallery',$img_box);
    if ($q)
    {
        return TRUE;
    }
    else return FALSE;
}

And to eat error
Severity: Notice
Message: Undefined variable: img_box
Please guide me

A:

The error could be this line in your controller:
$img_box[$i] = array ('img_url' => $dd[$i]);

Just before your for-loop add:
$img_box = [];

