Welcome Guest, Not a member yet? Register   Sign In
Update not working
#1

[eluser]Unknown[/eluser]
hi! my update function is not working because I have no idea on how to get the place the id of the record in the save function...
I have this model and controller to display the contents of the selected record in a view with text boxes:
model:
Code:
function upUser()
{
  $this->db->where('id', $this->uri->segment(3));
     $query = $this->db->get('users');
     return $query->result();
}
controller
Code:
function upUser()
{  //display in the textbox the result of the query
  $this->load->model('crudModel');
  $data['query']=
     $this->crudModel->upUser();
  $this->load->view('EditUsers',$data);
}
view
Code:
<?php echo form_open('login/updateUser'.$row->id); ?>
<?php
foreach($query as $row){
echo nl2br(" Username: ");
  echo form_input('username', set_value('username', $row->username));
    echo nl2br("\n \n Password: "); echo form_password('password', set_value('password', $row->password));
}
?>

<?php
  echo form_submit('submit', 'Save');
  echo form_close();?>

My problem is that when the SAVE button is pressed, is says that the update is successful, but it's actually not, because my save button is unable to get the current id.. how do i get it?
this is my model and controller for the save
model
Code:
function SaveupdateUsers($data)
{
  $this->db->where('id', $this->uri->segment(3));
  $this->db->update('users', $data);
}
controller
Code:
function updateUser()
{
  $data = array(
   'username' =>  $this->input->post('username'),
   'password' =>  $this->input->post('password'),
   'level' =>  $this->input->post('level')
  );
  

  $this->load->model('crudModel');
  
  $this->crudModel->updateUsers($data);
  $this->load->view('InsertUsers',$data);
}

thank you in advance for your help!




Theme © iAndrew 2016 - Forum software by © MyBB