Codeigniter - Input post array insert into mysql database -


i dont understand how insert row mysql table. if use code, add new row every post. rather that, want 1 row values.

here code sample.

html:

echo form_open('account/update');    echo "<p><label for='gender'>gender</label>  <input type='text' name='gender' id='gender'  value='".$gender."'  />     </p>   <p>   <label for='age'>age</label>   <input type='text' name='age' id='age' value='".$age."' />   </p>       <p>   <label for='bio'>biografie</label>   <input type='text' name='bio' id='bio' value='".$bio."' />   </p>       <p>   <label for='skills'>skills</label>   <input type='text' name='skills' id='skills' value='".$skills."' />   </p>    <p><input type='submit' value='save' /></p>";    echo form_close();  

controller:

function update()  {        $userid = $this->session->userdata("userid");       $datanew = array(            'userid' => $this->session->userdata("userid"),            'gender' => $this->input->post('gender'),            'age' => $this->input->post('age'),            'bio' => $this->input->post('bio') ,            'skills' => $this->input->post('skills')         ); $this->session->set_userdata($data);     $this->load->model('model_account');     $this->load->model("model_user");      $this->model_account->profile_insert($datanew);  $this->load->view("change_avatar");     redirect("account/show/".$this->session->userdata("userid")); } 

model:

function profile_insert($datanew)  {       $this->db->insert('profile', $datanew);  } 

i 5 rows if submit html form.

this works me: set userid unique , made if statement in controller ti switch between insert , update function.

controller:

    function update()  {         $datanew = array(            'userid' => $this->session->userdata("userid"),            'gender' => $this->input->post('gender'),            'age' => $this->input->post('age'),            'bio' => $this->input->post('bio') ,            'skills' => $this->input->post('skills')         );      $exists = $this->db->select('profile')->where('userid', $this->session->userdata("userid"));      if($exists)     {        $this->session->set_userdata($datanew);       $this->load->model('model_account');       $this->load->model("model_user");       $this->model_account->profile_update($datanew);       $this->load->view("change_avatar");       redirect("account/show/".$this->session->userdata("userid"));     }        else     {         $this->session->set_userdata($datanew);       $this->load->model('model_account');       $this->load->model("model_user");       $this->model_account->profile_insert($datanew);            $this->load->view("change_avatar");       redirect("account/show/".$this->session->userdata("userid"));     }     } 

model:

function profile_insert($datanew)  {            $this->db->insert('profile', $datanew);           }      function profile_update($datanew)  {            $this->db->update('profile', $datanew);               } 

thanks helping me


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -