Hi everybody, I’m trying to insert in a table data from checkboxes. They must be inserted in different rows in a column. But I don’t have how to insert them in more than one row. If I use this code, it is inserted only one value. My code in model is:
<?php
class User_model extends CI_Model {
public function __construct(){
parent:: __construct();
$this->load->database();
}
public function register()
{
$data=array(
'username'=>$this->input->post('username'),
'password'=>sha1($this->input->post('password')),
'first_name'=>$this->input->post('first_name'),
'last_name'=>$this->input->post('last_name'),
'email'=>$this->input->post('email'),
'phone'=>$this->input->post('phone'),
'year_birth'=>$this->input->post('birth'),
'user_info'=>$this->input->post('user_info')
);
$this->db->insert('users',$data);
$insert_id =$this->db->insert_id();
$role = array(
'role_id'=>$this->input->post('role_id'),
'user_id'=>$insert_id
);
$user_data=$this->db->insert('user_roles', $role);
return $user_data;
}My view with ckeckboxes is:
<input type='checkbox' name='role_id' value='1'/>Student
<input type='checkbox' name='role_id' value='2'/>Lecturer
<input type='checkbox' name='role_id' value='3'/>CustomerPacket Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.