Welcome Guest, Not a member yet? Register   Sign In
Insert with checkbox array
#1

[eluser]Mareli[/eluser]
Hello.. I hope you can help me

I need to insert multiple values into a database from an array of checkbox, but when i try to do it, I don't get the value of the checkbox, I always get "on". I left the code, so you may check it out, please Big Grin

Code:
&lt;input type="checkbox" name="etapas[] value="'.$row-&gt;idcentrocosto.'"/>.$row->nombre.<br>

Code:
{
if(is_array($_POST['etapas']) && count($_POST['etapas']) >= 1)
{            
   if($this->model->setMaterial($material))
   {
    for($i=0;$i<count($_POST['etapas']);$i++)
    {
                                          $this->model->setControlMaterial($_POST['etapas'][$i]);                                        
        }

   }
//redirect('materiales');
}
else
$this->error = "error en insercion de materiales";
$this->addMaterial();
}

And i get this
Code:
An Error Was Encountered
INSERT INTO controlmateria(idcentrocosto) VALUES( "on")

Somebody help me, please Sad
#2

[eluser]davidbehler[/eluser]
Try changing
Code:
name="etapas[]
to
Code:
name="etapas[]"

Maybe that helps.
#3

[eluser]Mareli[/eluser]
Thanks i can belive that i miss that ... :long: .. yeah that was the problem :red:
thank you
#4

[eluser]Phil Sturgeon[/eluser]
You can still use the input library for post values that are arrays. Some slightly more simple would be:

Code:
{
if( count($this->input->post('etapas')) >= 1 )
{            
   if($this->model->setMaterial($material))
   {
    foreach($this->input->post('etapas') as $val)
    {
        $this->model->setControlMaterial($val);                                        
    }

   }
//redirect('materiales');
}
else
$this->error = "error en insercion de materiales";
$this->addMaterial();
}

But now I'm just being picky. %-P




Theme © iAndrew 2016 - Forum software by © MyBB