Kiran Patil
Kiran Patil

Reputation: 1

how to store multiple checkbox values in database using codeigniter

<tr><th>Option Subject</th>
 <th>
<input type="checkbox" name="skills" id="skills[]" value="C++"> C++<br>
<input type="checkbox" name="skills" id="skills[]" value="JAVA"> JAVA<br>
<input type="checkbox" name="skills" id="skills[]" value="HTML"> HTML<br>
<input type="checkbox" name="skills" id="skills[]" value="PHP"> PHP<br>
<input type="checkbox" name="skills" id="skills[]" value="ASP.NET">ASP.NET<br>
<font color="#FF0000"><?php echo form_error('skills');?></font>
 </th>
</tr>

controler public function insert() { $skills=$this->form_validation->set_rules('skills', 'Option Subject','required');

$data = array(
    'skills' => implode(",", $skills);       
);
}



if(isset($options['skills'])) 
 $this->db->set('skills',($options['skills']));  
 $this->db->insert("regi_user");  
 return $this->db->insert_id();  

Upvotes: 0

Views: 1381

Answers (2)

Ravi Thanki
Ravi Thanki

Reputation: 289

To add multiple value in table try following code.

$language = $this->input->post('skills');

if (is_array($language) && !empty($language))
{
    foreach($language as $lan)
    {
        $insert['language'] = $lan;
        $this->db->insert("table name");
    }
}

Upvotes: 0

Roshni hegde
Roshni hegde

Reputation: 415

You have to convert imploded value to string.

Try the following code

 $data = array(
        'skills' => json_encode(implode(",", $skills));       
    );

    $this->db->insert("regi_user");  
    return $this->db->insert_id();  

Upvotes: 0

Related Questions