• 18 Jan, 2025

How to Delete Data in Database using Codeigniter

How to Delete Data in Database using Codeigniter

How to Delete Data in Database using Codeigniter

In this tutorial, we have handled Codeigniter delete Data using mysql,jQuery.  

We have handled tutorial in very easy steps. So let’s start the coding

Here put some sample code. for full source code click download now end of post

In datatable list view click on delete button

on click call delete function

registation-data-1.png

Delete  function in application/controllers/user.php

sample code

 function delete($userId)
   {
       $this->isLoggedIn();
       $this->load->model('User_model');
       $user = $this->User_model->getUser($userId);
       if ($user && !empty($user['img'])) {
           $imagePath = './uploads/' . $user['img'];
           if (file_exists($imagePath)) {
               unlink($imagePath);
           }
       }
       $this->User_model->deleteUser($userId);
       
   }

    
In user model deleteUser function call

sample code

 function deleteUser($userId)
   {
       $this->db->where('id', $userId);
       $this->db->delete('codeignitercrud');
   }


Download Full Code HERE 


Download Fome Here