ICTtask works best with JavaScript enabled.

 

PHP AJAX CRUD using MySqli - Delete

Live Demo
post thumbnail
Source Code
hi dear friend, In this tutorial is part four of php Ajax Crud System make by using Mysqli Extention. So in this tutorial we discussing on delete data from mysql database with delete from folder uploaded image by using php procedural form programming script ajax response without page refresh. so need to do this row id, we will get id by using data attribute value then we delete row to ajax response. we have seen not only how to you delete data from mysql Database even you can learn how to delete uploaded image from folder path without page refresh with we use When will successfully delete row data then we show success alert, We not use browser default alert, We have use sweet alert must be load sweet js file. If you can use so First include css and js files by using ofline Download or CDN links for these files. When we send data to action file by jquery ajax reponse. we have action method POST so we get value by $_POST[] Supper global variable then delete query will delete data from db_users_account database into table tbl_users. I have also provide sql file with source code see in this post. Now do this and Fellow our video tutorial We have also provide youtube Video in this post. In next video tutorial we will make discussing on how to fetch delete row from Mysql table and image from folder by using AJAX response. So please share my post and go to my youtube channel and subscribe and share videos with your friends. Thanks Next Tutorilas Link these:
    Files structure Fellow:
  • Application root folder
    • upload
    • //This Folder into upload files
    • action.php
    • //This file will handle for update data and Insert data to Database Table we used to our previews tutorial
    • fetchSingle.php
    • //This file will fetch data from mysql database table single roew information
    • index.php
    • //This file for table html markup for fetch data view into same form
    • select.php
    • //This file for view Data from Database Table

Sourse Code:

  • fetchSingle.php - This file for fetch single row data from Database Table

  • script>
  • Select.php - This file for view Data from Database Table

  • action.php - This file will handle for update row data and Insert data to Database Table we used to our previews tutorial

  • <?php 
      $connect = mysqli_connect("localhost","root","","db_phpajax");
    
      if (isset($_POST['action'])) {
        if ($_POST['action'] == 'delete') {
          $delteId = $_POST['delteId'];
          $deleteImg = $_POST['deleteImg'];
          $query = "DELETE FROM tbl_employee WHERE id='".$delteId."'";
          mysqli_query($connect,$query);
          unlink('upload/'.$deleteImg);
          echo 'deleted';
    
        }
        if ($_POST['action'] == 'create') {
          $firstName = mysqli_real_escape_string($connect,$_POST['firstName']);
          $lastName = mysqli_real_escape_string($connect,$_POST['lastName']);
          $designation = mysqli_real_escape_string($connect,$_POST['designation']);
    
          $imageName = img_upload($_FILES['image']);
    
          $query = "INSERT INTO tbl_employee(fName,   lName,designation,image) VALUES('".$firstName."','".$lastName."','".$designation."','".$imageName."')";
          if (mysqli_query($connect,$query)) {
            echo 'create';
          }
        }
    
        if ($_POST['action']=='update') {
          $updateId = $_POST['id'];
          $image = '';
          if ($_FILES['image']['name'] != '') {
            $image = img_upload($_FILES['image']);
            // Delete to database
            unlink('upload/'.$_POST['uploaded_image']);
          }else{
            $image = $_POST['uploaded_image'];
    
          }
    
          $firstName = mysqli_real_escape_string($connect,$_POST['firstName']);
          $lastName = mysqli_real_escape_string($connect,$_POST['lastName']);
          $designation = mysqli_real_escape_string($connect,$_POST['designation']);
          $query = "UPDATE tbl_employee SET   fName='".$firstName."', lName='".$lastName."', designation='".$designation."', image='".$image."' WHERE id = '".$updateId."'";
          mysqli_query($connect,$query);
          echo 'updated';
    
        }
      }
        
    
      
    
      function img_upload($file){
        $extention = explode('.', $file['name']);
        $newName   = rand().'.'.$extention[1];
        $designation = 'upload/'.$newName;
        move_uploaded_file($file['tmp_name'], $designation);
        return $newName;
      }
    
    ?>
    
  • index.php - This file for view single row data into table form Database Table

  • 
    
  • Database file sql

  • --
    -- Database: `db_phpajax`
    --
    -- --------------------------------------------------------
    --
    -- Table structure for table `tbl_employee`
    --
    CREATE TABLE `tbl_employee` (
      `id` int(11) NOT NULL,
      `fName` varchar(255) NOT NULL,
      `lName` varchar(255) NOT NULL,
      `designation` varchar(255) NOT NULL,
      `image` varchar(255) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `tbl_employee`
    --
    
    INSERT INTO `tbl_employee` (`id`, `fName`, `lName`, `designation`, `image`) VALUES
    (37, 'Roman ', 'Mondol', 'Teacher ', '22230.jpg'),
    (38, 'Aslam ', 'Hasib', 'Wordpress Developer', '23895.png'),
    (39, 'Md Ibrahim ', 'Islam', 'Writer', '10512.png'),
    (52, 'Aslam', 'Khan', 'Media Expert', '15945.png'),
    (59, 'Programmer', 'Rayhan Mondol', 'JAVA and PHP Developer', '28556.jpg');
    
    --
    -- Indexes for dumped tables
    --
    
    --
    -- Indexes for table `tbl_employee`
    --
    ALTER TABLE `tbl_employee`
      ADD PRIMARY KEY (`id`);
    
    --
    -- AUTO_INCREMENT for dumped tables
    --
    
    --
    -- AUTO_INCREMENT for table `tbl_employee`
    --
    ALTER TABLE `tbl_employee`
      MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=60;
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    
    

    Browse by Category

    php Ajax jQuery Codeigniter html css javascript

    Hi there! I am Rayhan Mondol, a PHP & JAVA Developer and ICT task is my programming blog. I'm fond of developing modern web applications. Contact me, I accept the paid task

    Latest Article

    post thumbnail

    Ajax Shopping Cart Customer Order View & account Update by using PHP OOP PDO(E-Commerce website-part 10)

    post thumbnail

    customer accout logout by using PHP OOP, PDO,COOKIE,AJAX(E-Commerce website-part 9)

    post thumbnail

    Customer Account Login by using PHP OOP PDO,AJAX (E-Commerce website-part 8)

    post thumbnail

    Customer Account Create by using PHP OOP PDO (E-Commerce website-part 7)

    post thumbnail

    Remove product from cart by using PHP OOP PDO(E-Commerce website-part 6)

    post thumbnail

    Ajax Shopping Cart update or Edit by using PHP OOP PDO (E-Commerce website-part 5)

    post thumbnail

    Ajax Shopping Cart View and calculate by using PHP OOP PDO (E-Commerce website-part 4)

    post thumbnail

    Drag and Drop Product Add to Cart by using PHP OOP PDO Ajax Jquery - E-Commerce project- (part-3)

    post thumbnail

    Product Add to Cart using PHP OOP PDO Ajax JQuery - E-Commerce project- (part-2)

    post thumbnail

    Create Dynamic Tabs using PHP OOP PDO - E-Commerce project- (part-1)

    post thumbnail

    CodeIgniter AJAX CRUD using Bootstrap Modal - Delete

    post thumbnail

    CodeIgniter AJAX CRUD using Bootstrap Modal Edit or Update

    post thumbnail

    CodeIgniter AJAX CRUD using Bootstrap Modal Read or view

    post thumbnail

    CodeIgniter AJAX CRUD using Bootstrap Modal-Create

    post thumbnail

    CodeIgniter AJAX CRUD(setup removing index.php from url)