1
votes

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?

1
If you're using Unix/Linux, the problem might be case-sensitive row names. Also, there is no $this->load->model('files'); line in your code. - Andrew Surzhynskyi
I was loading it at the top of the controller under parent::__construct();. - stinkysGTI
use $this->db->affedted_rows(); after the delete: it'll show you how many rows have been deleted. You may also use $this->db->last_query(); after the delete to know what query has been launched to the DDBB - Federico J.
Thank you for those, they're really useful. :) I tried them on my test MVC and they worked, but not on my actual MVC that I'm trying this on. I threw some echo's in the delete function and nothing was displayed as if it's not even running the function. Perhaps some kind of code conflict? - stinkysGTI

1 Answers

1
votes

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.