I cannot update data in Codeigniter database

I cannot update the data in the database. I don't know what happend.please is helping me. Display data Click the edit button. But I cannot edit the data in the database.

I posted the code below:

controller.php

public function ajax_update()
{
     $data = array(
            'placename' => $this->input->post('placename'),
            'description' => $this->input->post('description'),
            'tel' => $this->input->post('tel'),
            'latitude' => $this->input->post('latitude'),
            'longtitude' => $this->input->post('longtitude'),
            'placetype_id' => $this->input->post('placetype_id'),
            'province_id' => $this->input->post('province_id'),

        );
    $this->tblplace->update(array('placeid' => $this->input->post('placeid')), $data);
    echo json_encode(array("status" => TRUE));
}

      

Modal.php

 public function save($data)
{
    $this->db->insert('tblplace', $data);
    return $this->db->insert_id();
}

public function update($where, $data)
{
    $this->db->update('tblplace', $data, $where);
    return $this->db->affected_rows();
}

      

I can get data from the database to display in a textbox. But I can't update the data. I need help. Thank.

+3


source to share


2 answers


Your controller:

public function ajax_update()
{
    //You should also check the post array.
     $ajax_post_data = $this->input->post();
     log_message('debug', 'Ajax Post Data Array:' . print_r($ajax_post_data, TRUE)); 

    $placeid = $this->input->post('placeid');

     $data = array(
            'placename' => $this->input->post('placename'),
            'description' => $this->input->post('description'),
            'tel' => $this->input->post('tel'),
            'latitude' => $this->input->post('latitude'),
            'longtitude' => $this->input->post('longtitude'),
            'placetype_id' => $this->input->post('placetype_id'),
            'province_id' => $this->input->post('province_id'),

        );
    $this->load->model('tblplace');
    $updte_status = $this->tblplace->update($placeid, $data);
    if($updte_status == TRUE){
        echo json_encode(array("status" => true));
    } else {
       echo json_encode(array("status" => false)); 
    }
}

      

In the model:



public function update($where, $data)
{

    $this->db->where('id', $where)
             ->update('tblplace', $data);

    log_message('debug', 'Last Update Query:' . print_r($this->db->last_query(), TRUE));
    log_message('debug', 'Affected row count:' . print_r(count($this->db->affected_rows()), TRUE));
    if ($this->db->affected_rows() === 1) {
        return TRUE;
    }else{
        return FALSE;
    } 
}

      

Hope this is clear and helps you update your data.

0


source


There is no update in your function where



public function update($where, $data)
    {
        $this->db->where($where);
        $this->db->update('tblplace', $data);
        return $this->db->affected_rows();
    }

      

0


source







All Articles