0

I'm beginner in codeigniter.I'm trying to delete a row from my table.I tried the following code.But it's not working.

This is url i'm passing.

<a href="./Delete_user/<?= $thisid ?>">Delete User</a>

This is my controller (Delete_user.php).

<?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    class Delete_user extends CI_Controller {
    public function delete_row($id) {
    $this->load->model('Delete_selecteduser');
    $where = array('id' => $id);
    $this->Delete_selecteduser->delete_user('users', $where);
}

And here is my model (Delete_selecteduser.php).

<?php
    class Delete_selecteduser extends CI_Model {
    public function __construct() {
    $this->load->database();
    }
    public function delete_user($table, $where = array()) {
    $this->db->where($where);
    $res = $this->db->delete($table);
    if ($res)
    return TRUE;
    else
    return FALSE;
    }
}

And also I want to display a message that record has been deleted successfully.Please help me to fix this.

Preshan Pradeepa
  • 698
  • 14
  • 31

1 Answers1

0

i suggest that the function must be

public function  delete_user($table, $where = array()) {
    $this->db->where($where);
    $this->db->delete($table);
    $res = $this->db->affected_rows();
    return $res;
}

in this way you always have a answer, 0 for a no deleted row or 1 if you delete only a row

clairerb6
  • 99
  • 8
  • could be a PHP error, see the logs for a correct answer of the 404 error, but usually is a 500 error. You remove the "index.php" from the URL, right? generally the logs are in the /var/log/httpd/error_log but you can see this if you have a doubt https://stackoverflow.com/questions/5127838/where-does-php-store-the-error-log-php5-apache-fastcgi-cpanel – clairerb6 May 27 '16 at 14:35