There are probably more roads to the same solution, but I'll try to describe the approach that is most common in CI.
This is a very basic example, using model, view and controller.
Controller: Stud_controller
PHP Code:
public function update_student($id)
{
$this->load->model('stud_model');
if ( ! $this->input->post('submit') ) {
// if the form is not yet submitted, then show the form
$data['record'] = $this->stud_model->get_student($id);
$this->load->view('student_form',$data);
}
else {
// form is submitted; update the record in the database
$data = array(
'name' => $this->input->post('name'),
'roll_no' => $this->input->post('roll_no')
);
$this->stud_model->update_student($id,$data);
redirect('/'); //return to your home page
}
}
Model: stud_model
PHP Code:
public function get_student($id)
{
//fetch a record from the table 'students', for the given id
$query = $this->db->get_where('students', 'id=' . $id, 1);
if ($query->num_rows() > 0) {
return $this->query->row_array();
}
else {
return FALSE;
}
}
public function update_student($id,$data)
{
//update the record in the table 'students'
$this->db->update('students', $data, 'id=' . $id);
}
View student_form
PHP Code:
<?php
if (! $record) {
show_error('There is no student with this id in the database');
die();
}
echo form_open(); //the form will be submitted to the same url as it was called from
echo 'Name: ' . form_input('name',$record['name']) . '<br />';
echo 'Roll_no: ' . form_input('roll_no', $record['roll_no']) . '<br />';
echo form_submit('submit','Submit form'); //important: the submit button should have a name, in this case: 'submit'
echo form_close();
?>