I'm working on a project where I need to add multiple selected values into a single Column using Php CodeIgniter.
Here's the actual problem statement: 
I have a INT column **total\_persons** to store the number of total people (i.e. 5) and a VARCHAR column **person\_names** which would store the names of those 5 people.

To select multiple users from dropdown, I'm using Select2 library.
But when I submit the data, following error pops up

**The Person Names field is required.**
Of course it is because I've set validation rules on the form as follows:

**$this->form\_validation->set\_rules('person\_names','Person Names','required');**

I don't understand why it does not take any value when there are 5 user names selected.

If I add ID of a single user (keeping the column to be INT) instead of multiple selected values, it works fine and sends data in DB. But when I try to store multiple usernames, it throws the error I pasted above.

Here's my **Expense.php** code from Controller 

```
    function add()
    {   
        $this->load->library('form_validation');

        $this->form_validation->set_rules('expense_type','Expense Type','required');
        $this->form_validation->set_rules('person_names','Person Names','required');
        $this->form_validation->set_rules('total_persons','Total Persons','required');
        $this->form_validation->set_rules('expense_amount','Expense Amount','required');
        $this->form_validation->set_rules('expense_details','Expense Details','required');
        $this->form_validation->set_rules('date_added','Date Added','required');

        if($this->form_validation->run())     
        {   
            $params = array(
                'expense_type' => $this->input->post('expense_type'),
                'total_persons' => $this->input->post('total_persons'),
                'person_names' => $this->input->post('person_names'),
                'expense_amount' => $this->input->post('expense_amount'),
                'expense_details' => $this->input->post('expense_details'),
                'date_added' => $this->input->post('date_added'),
                'update_date' => $this->input->post('update_date'),
            );

            print_r($params);
            exit();

            $expense_id = $this->Expense_model->add_expense($params);
            redirect('expense/index');
        }
        else
        {
            $this->load->model('Expense_type_model');
            $data['all_expense_type'] = $this->Expense_type_model->get_all_expense_type();

            $this->load->model('User_model');
            $data['all_users'] = $this->User_model->get_all_users();

            $data['_view'] = 'expense/add';
            $this->load->view('layouts/main',$data);
        }
    }  

```

**Expense\_Model.php** 

```
    function add_expense($params)
    {
        $this->db->insert('expense',$params);
        return $this->db->insert_id();
    }

```

**view.php**

```
    <div class="col-md-6">
        <label for="person_names" class="control-label"><span class="text-danger">*</span>Person Names</label>
        <div class="form-group">
            <select name="person_names[]" class="form-control multiselect" multiple="multiple">
                <option value="">select user</option>
                    <?php 
                        foreach($all_users as $user)
                        {
                            $selected = ($user['user_name'] == $this->input->post('person_names')) ? ' selected="selected"' : "";

                            echo '<option value="'.$user['user_name'].'" '.$selected.'>'.$user['user_name'].'</option>';

                        } 
                    ?>
           </select>

            <span class="text-danger"><?php echo form_error('person_names');?></span>
        </div>
    </div>

```

If I'm not missing some key point, the code should add five names in the user\_name field as follows? 
**["user1", "user2", "user3", "user4", "user5"]**
(This is my assumption, apologies if I've guessed it wrong)

Can someone help me figure out where am I making a mistake?

Thanks very much in advance.