0

I tried to create an activity log in Codeigniter based on changes in input made by the user and produce an output like this

Output : User1 Changes: Address (Street A) becomes (street B), date of birth (March 10, 2000) becomes (March 20, 2000), Phone number (0000) becomes (11111).

When I Submit my form, I can find out which data has changed, for example address, from address A to address B. I want store on database for Logs. I might have been able to enter the data into the database, but I still don't know how to get the output data, I have try with to use jQuery but not success. is there a function to do that in codeigniter?

This my input form.

 <?php echo form_open(base_url('update_profile'), 'class="form-horizontal"');  ?> 
  <label for="address">Address:</label><br>
  <input type="text" id="address" name="address" value="Street B"><br>
  <input type="hidden" id="old_address" name="old_address" value="Street A"><br>

  <label for="birth">Date Birth:</label><br>
  <input type="text" id="birth" name="birth" value="March 20, 2000"> 
  <input type="hidden" id="old_birth" name="old_birth" value="March 10, 2000"> 

  <label for="phone">Phone number:</label><br>
  <input type="text" id="phone" name="phone"  value="11111">
  <input type="hidden" id="old_phone" name="old_phone" value="0000">

  <label for="email">Email:</label><br>
  <input type="email" id="email" name="email">
<?php echo form_close(); ?>

My controller

public function update_profile(){

        $is = $this->session->userdata('id');
        $this->form_validation->set_rules('phone', 'Phone', 'trim');

        if ($this->form_validation->run() == FALSE) {
                $errors = validation_errors();
                echo $errors;
        }
        else{
            $data = array(
                 'address' => $this->input->post('address'),
                 'birth' => $this->input->post('birth'),
                 'phone' => $this->input->post('phone'),
                 'email' => $this->input->post('email'),

            );

            $data   = $this->security->xss_clean($data);
            $result = $this->data_user->update_model_profile($data, $id);
            $result = true;

            if ($result) {
                echo $result;
            }
        }  
}   

and this my model.

    public function update_model_profile($data, $id){
        $this->db->where('user_id', $id);
        $this->db->update('data_profile', $data);
        return true;
    }   
dhannyjsb
  • 3
  • 1
  • 4
  • for getting data from database you simply make a function in model like update function and then you can get this in controller or you want something else?? – Nadeem Ijaz May 17 '20 at 05:14
  • What do you mean by how to get the output data? Please explain your issue – sauhardnc May 17 '20 at 05:34
  • I mean, when I click submit, I can find out which data has changed, for example address, from address A to address B. just like this https://stackoverflow.com/questions/29118178/input-jquery-get-old-value-before-onchange-and-get-value-after-on-change , but for all Input. @sauhardnc – dhannyjsb May 17 '20 at 06:56
  • thanks, but I won't getting data from database. I want get logs data and I can find out which data has changed. @NadeemIjaz – dhannyjsb May 17 '20 at 07:00

1 Answers1

0

You can Keep a copy of data fetched from database in an array and then compare it with data submitted by the form and can get what values are changed by the user.

macsys
  • 21
  • 4