ICTtask works best with JavaScript enabled.

 

PHP OOP with AJAX CRUD using mysqli - Create or insert

Live Demo
post thumbnail
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 create or Insert or Add data into Mysql Database table 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 go to create a create form we use this most populer bootstrap framework with propeller framework. If you can use so include css and js files by Download or use CDN link. First we can get value of fields by using jquery 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. We not use browser default alert for this, we will use sweet alert for this. If you may use so include js file by using ofline CDN link or Download.I used to by download my directory. so after ajax respose to action.php file and request method is post so we will get value by use supper global variable post($_POST[]). We will insert data into employee_account database tbl_employee table. I have also provide sql file with source code see in this post. 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. so we have a hidden field value assign value create if this value create so will insert by using insert jqery using mysqli database connection. If will successfull insert so return a string jquery call back function get string after show success alert. We have using sweet alert not Browser Default alert . 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 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'] == '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)