简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM