codeigniter – Can’t delete or modify database

This is my first time using codeigniter to build a site, so I’m pretty new to it. I have an admin page where videos can be approved or deleted and neither of the functions are working. When the links are clicked it just loads the page and nothing has happened, and there isn’t any change in the database. I went here https://www.codeigniter.com/user_guide/database/query_builder.html#deleting-data and tried this:

$this->db->delete('files', array('id' => $id));

It changes the url to what I believe is correct: /profile/delete/29

I’m loading the model which contains this simple function:

function delete($fileid){
    //$this->db->query("DELETE FROM files WHERE ID = '$fileid'");

    $this->db->delete('files', array('ID' => $fileid));
}

Then running this in my controller:

function delete($id){
    //$this->db->query("DELETE FROM files WHERE ID=$id");

    $this->files->delete($id);

    redirect('profile');
}

Can somebody please tell me what I’m doing wrong?

Answer

Try like this:

function delete($fileid){
    $this->db->where('ID', $fileid);
    $this->db->delete('files');
}



function delete($id){
   $this->load->model('files');

    $this->files->delete($id);

    redirect('profile');
}

If you have any error, just write it on comment.