How to edit Records using CodeIgniter



PHP Snippet 1:

$this->db->update('booking', $booking);

PHP Snippet 2:

function update()
{
    $booking=array(
        'name'=>$this->input->post('name'),
        'nationality'=>$this->input->post('nationality'),
        'number_of_guest'=>$this->input->post('number_of_guest'),
        'date'=>$this->input->post('date'),
        'package'=>$this->input->post('package'),
        'request'=>$this->input->post('request')
        );

    $this->db->where('id', 1);
    $this->db->update('booking', $booking);
}

PHP Snippet 3:

`    function update()
     {
        $booking=array(
        'name'=>$this->input->post('name'),
        'nationality'=>$this->input->post('nationality'),
        'number_of_guest'=>$this->input->post('number_of_guest'),
        'date'=>$this->input->post('date'),
        'package'=>$this->input->post('package'),
        'request'=>$this->input->post('request')
        );    
    $this->db->where('<primary_key>', <pri_key_value>);
    $error =  $this->db->update('<table_name>', $booking);`,

PHP Snippet 4:

<?php $id = "1" ?>
<?php echo form_open_multipart("testimonials_controller/testimonials_edit/$id");?>
    <table width="500" class="table" cellpadding="0" cellspacing="2" align="center">
        <tr>
            <td width="130" align="left">Author: </td>
            <td><?php echo form_input($title); ?></td>
        </tr>
        <tr>
            <td width="130" align="left">Content: </td>
            <td><?php echo form_textarea($content); ?></td>
            <script type="text/javascript">
            CKEDITOR.replace( 'contentbox' );
            </script>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><?php echo form_submit('submit', 'Submit');?>
            </td>
        </tr>
    </table>
<?php echo form_close();?>

PHP Snippet 5:

function updatetestimonials($id, $data)
    {
        $this->db->where('id', $id);
        $this->db->update('testimonials', $data);
    }

PHP Snippet 6:

function testimonials_edit($id)
    {
            $this->load->helper('form');  
            $this->load->helper('html');
            $this->load->library('form_validation');
            $this->load->model('testimonials_model');
            $this->data=$this->testimonials_model->general();
            $testimonials = $this->testimonials_model->get_testimonials($id);

        $this->data['title'] = 'Edit Testimonial';

        //validate form input
        $this->form_validation->set_rules('title', 'Author', 'required|xss_clean');
        $this->form_validation->set_rules('contentbox', 'content', 'required|xss_clean');
        if (isset($_POST) && !empty($_POST))
        {       

            if ($this->form_validation->run() === true)
            {
                $data = array(
                'title'=>$this->input->post('title'),
                'content'=> $this->input->post('contentbox'),
            );

                $this->testimonials_model->updatetestimonials($id, $data);
                $this->session->set_flashdata('message', "<p>Testimonial is updated successfully.</p>");

                redirect('testimonials_controller/testimonials_edit/'.$id);
            }           
        }

        $this->data['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));

        $this->data['testimonials'] = $testimonials;

        //display the edit product form


        $this->data['title'] = array(
            'name'      => 'title',
            'id'        => 'title',
            'type'      => 'text',
            'style'     => 'width:300px;',
            'value'     => $this->form_validation->set_value('title', $testimonials['title']),
        );

        $this->data['content'] = array(
                'name'      => 'contentbox',
                'id'        => 'contentbox',
                'type'      => 'text',
                'cols'      =>  60,
                'rows'      =>  5,
                'style'     => 'width:250px;',
                'value'     => $this->form_validation->set_value('contentbox',$testimonials['content']),
        );

        $this->load->view('testimonials_edit', $this->data);
    }