php - How to insert two diffrent values into same field? -


i want insert 2 different values database.

the field names same want 2 different values saved there.

for have form creates organization. in have 2 fields sales , tech. insert name,last_name,email sales , tech well. whatever values there save users table , save id organization table.

first want insert sales person information , tech person information , id , save in organization

this code:

        $this->data['company'] = $this->company_m->get_new();         $this->data['user'] = $this->secure_m->get_new();         $rules = $this->company_m->rules_admin;          $this->form_validation->set_rules($rules);           if ($this->form_validation->run() == true)         {                $data =$this->secure_m->array_from_post(array('first_name','last_name','email'));              $sales_id = $this->secure_m->save($data,$id);                  $data =$this->secure_m->array_from_post(array('first_name','last_name','email'));              $tech_id = $this->secure_m->save($data,$id);                  $data = $this->company_m->array_from_post(array('org_name','dba','addr1','addr2','city','state','country','pin','sales_id','tech_id','tax_number','comment','url'));                  $data['sales_id']= $sales_id;             $data['tech_id']= $tech_id;              $this->company_m->save($data, $id);               redirect('admin/company');          }                                             // load view         $this->data['subview'] = 'admin/company/add';         $this->load->view('admin/_layout_main', $this-> 

array post code

public function array_from_post($fields){     $data = array();     foreach ($fields $field) {         $data[$field] = $this->input->post($field);     }     return $data; } 

you're trying values wrong keys. i.e. have first_name_sales , first_name_tech, read first_name.

try

$data_tech = $this->secure_m->array_from_post(array('first_name_tech','last_name_tech','email_tech','tech')); // ...     $data_sales = $this->secure_m->array_from_post(array('first_name_sales','last_name_sales','email_sales','sales')); // ... 

also should set_value corresponding objects instead of same $user. pass $user_tech , $user_sales view. smth like

$this->load->view('admin/_layout_main', ['user_tech' => $data_tech, 'user_sales' => $data_sales]);  

Comments