I want to create a user registration form where I allow user to be able to put as many emails and phones as they want just like Google Contacts.

I already created the form that allow user to add or remove the input field for emails and phones dynamically. here's the image of it:
[User Registration Form](https://i.stack.imgur.com/XUEvL.png)

this is the model script I use..

```
public function store_email() {
        if (! $this->validate_email()) return FALSE;
        $this->db->trans_begin();
        try {
            $this->db->insert($this->table_user, $this);
            $id = $this->db->insert_id();
            foreach ($this->email as $key => $value) $this->email[$key]['user_id'] = $id;
            $this->db->insert_batch($this->table_email, $this->email);
        } catch (Exception $e) {
            return FALSE;
        }
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            return FALSE;
        } else {
            $this->db->trans_commit();
            return TRUE;
        }
    }
public function store_phone() {
        if (! $this->validate_phone()) return FALSE;
        $this->db->trans_begin();
        try {
            $this->db->insert($this->table_user, $this);
            $id = $this->db->insert_id();
            foreach ($this->phone as $key => $value) $this->phone[$key]['user_id'] = $id;
            $this->db->insert_batch($this->table_phone, $this->phone);
        } catch (Exception $e) {
            return FALSE;
        }
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            return FALSE;
        } else {
            $this->db->trans_commit();
            return TRUE;
        }
    }

```

this is the controller script I use..

```
public function store() {

        $this->model->first_name = $this->input->post('first_name', TRUE);
        $this->model->middle_name = $this->input->post('middle_name', TRUE);
        $this->model->last_name = $this->input->post('last_name', TRUE);
        $this->model->email = [];
        $this->model->phone = [];

        foreach ($this->input->post('label_id', TRUE) as $key => $value) $this->model->email[$key]['label_id'] = $value;
        foreach ($this->input->post('email', TRUE) as $key => $value) $this->model->email[$key]['email'] = $value;
        foreach ($this->input->post('label_id', TRUE) as $key => $value) $this->model->phone[$key]['label_id'] = $value;
        foreach ($this->input->post('phone', TRUE) as $key => $value) $this->model->phone[$key]['phone'] = $value;

        if ($this->model->store_email() === TRUE) {
            if ($this->model->store_phone() === TRUE) {
                $notification = 'Register success! You may login now!';
            } else {
                $notification = 'Register fail!';
            }
        } else {
            $notification = 'Register fail!';
        }

        $this->CI->session->set_flashdata('Success',$notification);
        redirect(base_url().'login');

    }

```

I run this code and it gives me error saying Array to String conversion and I am not able to store any data into database.
any help would be really appreciated.

Updated:

here's the error I get:

```
A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: database/DB_query_builder.php

Line Number: 1496

Backtrace:

File: C:\xampp\htdocs\ci-master-detail-trans\application\models\Customer_model.php
Line: 103
Function: insert_batch

File: C:\xampp\htdocs\ci-master-detail-trans\application\controllers\Customer.php
Line: 50
Function: store

File: C:\xampp\htdocs\ci-master-detail-trans\index.php
Line: 292
Function: require_once

```

the table I use for this:

* Table\_User (id, name, username, password)
* Table\_Email (id, email, user\_id, label\_id)
* Table\_Phone (id, phone, user\_id, label\_id)
* Table\_Label (id, label)