I want to update value from DB. but my code won’t work

Main

public function update_sample(){

$id3 = sanitize($this->input->post(‘id3’));

    $sample3 = sanitize($this->input->post('sample3'));

    

    if($this->session->userdata('position_id') != ""){
        $username = $this->model->get_users($this->session->userdata('user_id'))->row()->username;
        $query = $this->model->update_sample($data);
        $data = array(
            "success" => 1,
            "message" => 'Note: You have successfully updated');
    }else{
        $this->logout();
    }
    generate_json($data);
}

model

public function update_sample($sample){
        $sql = "UPDATE test SET  sample=? WHERE id=? AND enabled= 1";
        $data = array($sample);
        return $this->db->query($sql, $data);
    }

js

$("#table-grid").delegate(".btnUpdate", "click", function(){
        var id = $(this).data('value');
        $.ajax({
            type: 'post',
            url: base_url+'Main/view_details',
            data: {'id3': id},
            success: function(data){
                var res1 = data.result1;
                if(data.success==1){
                    
                    document.getElementById("sample3").value = res1[0].samples;

                    $('#update').modal();
                }           
            }
        });
    });

I want to update Data from database i’ve been stuck here for long.