/* FB instanr*/

PHP OOP with AJAX CRUD using mysqli - Edit or Update

Live Demo
PHP OOP with  AJAX CRUD using mysqli - Edit or Update
Source Code
hi there, this tutorial of Creating CURD application system by using PHP OOP(Object Oriented PHP) programming and Msqli Database extention With jquery ajax response. so in this tutorial you will learn how can you Edit or Update by using object oriented form programming style and without page refresh with upload image file by using ajax response. So You may also check demo online.Our have also provide demo link And source code download link with this tutorial post. php object oriented form programming is most populer for easy to handle any project. So if you use this programming style then so easy to develop any project for you more than php procedural form coding style. First we fetch single data of specific row data then show on eash field by using jquery, ajax then validation each empty field and Image file upload befor validation checking. If Invalid format is so we will alert show for this if else so send data each field value by using ajax response. Then same functionality like insert data, so We will just execute update query. Now do this and follow our video tutorial We have also provide youtube Video in this post. In next video tutorial we will make discussing on how to select rows from Mysql table 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 images
    • Employee.php
    • //This file will handle for database connection query execute
    • action.php
    • //This file will handle for Insert data into Database Table
    • index.php
    • //This file for Create form

Sourse Code:

  • Employee.php - database connection and database query

  • <?php 
     class Employee{
        public $connect;
        private $host = "localhost";
        private $userName = "root";
        private $userPass = "";
        private $BDName   = "employee_account"; 
    
        public function __construct(){
          $this->BDConnect();
        }
    
        public function BDConnect(){
          $this->connect = mysqli_connect($this->host,$this->userName,$this->userPass,$this->BDName);
        }
        public function query_execute($sql){
          return mysqli_query($this->connect,$sql);
        }
        public function upload($file){
        $extention =  explode('.', $file['name']);
        $newName =  rand().'.'.$extention[1];
        $destination = './upload/'.$newName;
        move_uploaded_file($file['tmp_name'], $destination);
        return $newName;
        }
    
      }
    
    ?>
    
  • action.php

  • <?php 
        include 'Employee.php';
        $employeeObj = new Employee();
      if (isset($_POST['action'])) {
        if ($_POST['action'] == 'update') {
          $image = '';
          $id = $_POST['id'];
          $uploaded_image = $_POST['uploaded_image'];
          if ($_FILES['image']['name'] !='') {
            $image = $employeeObj->upload($_FILES['image']);
            unlink('upload/'.$uploaded_image);
          }else{
            $image =$uploaded_image;
          }
          $name = mysqli_real_escape_string($employeeObj->connect,$_POST['name']);
          $salary = mysqli_real_escape_string($employeeObj->connect,$_POST['salary']);
          $sex = mysqli_real_escape_string($employeeObj->connect,$_POST['sex']);
    
          $sql = "UPDATE tbl_employee SET name='".$name."',salary='".$salary."',sex='".$sex."',image='".$image."' WHERE id ='$id'";
    
          $employeeObj->query_execute($sql);
          echo 'updated';
        
        }
        if ($_POST['action'] =='fetchSingle') {
          $output = '';
          $editId = $_POST['editId'];
    
          $sql = "SELECT * FROM  tbl_employee WHERE id='$editId'";
          $data  = $employeeObj->query_execute($sql);
          while ($row  = $data->fetch_assoc()) {
            $output['name'] = $row['name'];
            $output['salary'] = $row['salary'];
            $output['sex'] = $row['sex'];
            $output['image'] = $row['image'];
            $output['uploaded_hidden_image'] = '';
    
          }
          echo json_encode($output);
    
        }
        if ($_POST['action'] =='load') {
          // Load data
          $output = '';
          $sql = "SELECT * FROM tbl_employee ORDER BY id DESC";
          $data = $employeeObj->query_execute($sql);
          $output .= '
          Employee Picture
          Employee Name
          Employee Salary
          Edit
          Delete
        ';
          while ($row = $data->fetch_assoc()) {
            $output .= '
          
          '.$row['name'].'
          '.$row['salary'].' ৳
          
          
        ';
          }
    
          echo $output;
          
    
        }
        if ($_POST['action'] == 'create') {
          // Do Somthing.......
          $image = '';
          $name = mysqli_real_escape_string($employeeObj->connect,$_POST['name']);
          $salary = mysqli_real_escape_string($employeeObj->connect,$_POST['salary']);
          $sex = mysqli_real_escape_string($employeeObj->connect,$_POST['sex']);
          if ($_FILES['image']['name'] != '') {
            $image = $employeeObj->upload($_FILES['image']);
          }else{
            $image = '';
          }
          $sql = "INSERT INTO tbl_employee(name,salary,sex,image) VALUES('".$name."','".$salary."','".$sex."','".$image."')";
          $employeeObj->query_execute($sql);
          echo 'created';
    
    
        }
      }
    ?>
    
  • index.php

  • 
    
  • Database file sql

  • 
    --
    -- Database: `employee_account`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `tbl_employee`
    --
    
    CREATE TABLE `tbl_employee` (
      `id` int(11) NOT NULL,
      `name` varchar(255) NOT NULL,
      `salary` varchar(255) NOT NULL,
      `sex` varchar(11) NOT NULL,
      `image` varchar(50) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `tbl_employee`
    --
    
    INSERT INTO `tbl_employee` (`id`, `name`, `salary`, `sex`, `image`) VALUES
    (14, 'Tisha', '1500', '2', '25078.jpg'),
    (15, 'Programmer Rayhan Mondol', '50,000', '1', '23031.jpg'),
    (25, 'Rakib Ali', '20000', '1', '32308.png');
    
    --
    -- 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=26;
    /*!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)