Welcome Guest, Not a member yet? Register   Sign In
Edit vs update
#2

[eluser]SitesByJoe[/eluser]
You're right. That works.

Things you can do to clean up a little more:

1. Make and use the form_validation config file (config/form_validation.php) and use it like described in the user guide.

2. You can just have one function do both operations (edit and update) using this structure:

Code:
function edit()
{
    if ($this->form_validation->run('see #1') == FALSE)
    {
         // show the form or error messages
    }
    else
    {
         // process our form stuff into an array
         $record = array('fieldname' => $this->input->post('fieldname'));

         // save the record changes
         $this->db->where('id', $this->input->post('id');
         $this->db->update('table', $record);

         // make a success message to potentially show our user
         $this->session->set_flashdata('message', 'success!');

         // move along to new screen
         redirect('success-page');
    }
}


Messages In This Thread
Edit vs update - by El Forum - 02-07-2011, 07:13 PM
Edit vs update - by El Forum - 02-07-2011, 09:03 PM
Edit vs update - by El Forum - 02-07-2011, 09:36 PM
Edit vs update - by El Forum - 02-08-2011, 10:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB