0

Could you check why the row cannot be deleted. I get database error: Deletes are not allowed unless they contain a "where" or "like" clause. Your help is highly appreciated

Here is my view:

                    <td><a href="<?php echo base_url("admin/delete_row/".$user['user_id']
                     ); ?>">Delete</a></td>  

Here is my controller:

public function delete_row() {

    if ($this->session->userdata('is_admin_logged_in')){

        $this->load->model("model_admin");
        $this->model_admin->did_delete_row();

        }
        else
        {
            redirect('admin/login'); 
        }

    }

Here is my Model:

public function did_delete_row(){ 

    $this->db->where('user_id', $this->input->get('user_id'));
    $this->db->delete('users'); 

    if ($this->db->delete('users')) 

        {return true;}

        else

        {return false;}

                }
NiceTry
  • 360
  • 5
  • 7
  • 16

2 Answers2

2

try this :

<td><a href="<?php echo base_url("admin/delete_row/".$user['user_id']); ?>">Delete</a></td>

check your URL Helper is loaded . and value of $user['user_id'] is set

if data in object format then simply replace $user['user_id'] with $user->user_id

<td><a href="<?php echo base_url("admin/delete_row/".$user->user_id); ?>">Delete</a></td>

controller:

public function delete_row(){
    $id = $this->uri->segment(3)
    if ($this->session->userdata('is_admin_logged_in'))
    {
        $this->load->model("model_admin");
        $this->model_admin->did_delete_row($id);
    }
    else
    {
        redirect('admin/login'); 
    }

}

Model:

public function did_delete_row($id){ 

    if ($this->db->delete('users', array('user_id' => $id))) 
    {
        return true;
    }
    else
    {
        return false;
    }

}
Haseeb
  • 2,214
  • 1
  • 22
  • 43
  • URL helper is loaded. I tried in the way you described but it still does not show the link – NiceTry Apr 17 '14 at 06:41
  • 1
    check value of $user['user_id'] is set ?? – Haseeb Apr 17 '14 at 06:46
  • I have just added my view code. Could you check if $user['user_id'] is set? – NiceTry Apr 17 '14 at 07:12
  • @TProDeveloper replace $user['user_id'] with $user->user_id. – Haseeb Apr 17 '14 at 07:20
  • I did it. Now link appears but when I click on the link it shows error "Deletes are not allowed unless they contain a "where" or "like" clause.". Could you help me please. – NiceTry Apr 17 '14 at 07:39
  • I have just added my controller and model codes. Could you please check them. – NiceTry Apr 17 '14 at 07:46
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/50847/discussion-between-haseeb-and-tprodeveloper) – Haseeb Apr 17 '14 at 07:47
  • Hi Haseeb, Hope you are doing well:) Could you please check my question. Maybe you can help me to find the mistake. http://stackoverflow.com/questions/23911438/codeigniter-get-data-from-database-using-ajax-in-codeigniter – NiceTry May 29 '14 at 04:13
  • @TProDeveloper join this chat room http://chat.stackoverflow.com/rooms/54693/codeigniter-issue – Haseeb May 29 '14 at 05:22
0

You can try this

 <td>
   <a href=<?php echo base_url()."admin/delete_row/".$user['user_id'];?>>Delete</a>
</td>
mmBs
  • 8,421
  • 6
  • 38
  • 46
Kedar B
  • 774
  • 5
  • 18
  • 47