0

I'm saving my data with Array, look:

Get data:

$data['address'] = $this->input->post('address');

Save:

$this->load->model('mymodel');
if($this->inscricao_model->mymodel($data)){
echo "success";
}

But now, I'll have another field (checkbox) with names as array, how to I save this information? My check box:

<input type="checkbox" name="skills[]" id"skill" />
<input type="checkbox" name="skills[]" id"skill" />

I was trying, but generate a error:

$data['skills'] = $this->input->post('skills');

Message: Array to string conversion
5
  • what type is $this->input->post('skills') could you post var_dump($this->input->post('skills')) Commented Mar 28, 2012 at 13:38
  • array(2) { [0]=> string(8) "testss" [1]=> string(7) "tessssst" } @dm03514 Commented Mar 28, 2012 at 13:42
  • Your checkbox is multi select type or single select? Commented Mar 28, 2012 at 13:47
  • There is a multiple selection so it returns array so you have to take loop to get values from array. Commented Mar 28, 2012 at 13:49
  • Yes, but how I do in this case? I'm trying but not work. @srbhbarot Commented Mar 28, 2012 at 13:50

1 Answer 1

3

You can use values of checkbox like this:

foreach( $this->input->post('skills') as $r )
{
    echo $r;
}

Edit: You can do something like this:

    $i=1;
    foreach( $this->input->post('skills') as $r )
    {
        $data['field'.$i]= $r;
        $i++;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

but I want save each checkbox data in a diferent column in my database. this way I print everything together. @srbhbarot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.