ICTtask works best with JavaScript enabled.

 

Ajax, jQuery Datatables Server Side CRUD - Create Data by using PHP OOP, PDO (Part-2)

Live Demo
post thumbnail
Source Code
Our previous tutorial, we have made view or select data by using jQuery server side table. In tutorial session we makes of Creating CURD Application system by using PHP OOP With jquery ajax. So I have already create form html markup using bootstrap modal with propeller framework. Now we will write jquery code for form validation, we checking each empty field and image file valid format. Then we will be try to send form data by using ajax response. We have create a hidden action field if this value crteate then Insert data into mysql database table. We have created our previos tutorial DB class now we create a insert method for data insert like dynamic query. In this tutorial you can learn how to upload image by using Ajax Response Without page Refresh not only how can you create or insert data into mysql Database with php object oriented programming method. Object oriented programming easy to handle any project more than php procedural programming method. If data insert into database table successfull so return a string then jquery ajax call back function show a successfull alert and We have created jquery data tavble now just refresh table by use ajax reload method like table.ajax.reload() then will refresh and then show new data into table. So jquery data table very usefull plugin for data table and easy make responsive data table just write responsive:true into DataTable method option and must be loaded jquery responsive css. I hope you understand.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 insert or add data into database table useing server side jquery table. 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
    • DB.php
    • //This file will handle for database connection and execute query
    • index.php
    • //This file for view table

Sourse Code:

  • DB.php - database connection and query Execute

  • <?php
        class DB{
        public $DBconnect;
        private $hostName = "localhost";
        private $userName = "root";
        private $userPass = "";
        private $DBName = "office_employee";
    
        public function __construct(){
          $this->DBConnection();
        }
        public function DBConnection(){
          try{
            $this->DBconnect = new PDO('mysql:host='.$this->hostName.';dbname='.$this->DBName,$this->userName,$this->userPass);
          }catch(PDOException $e){
            echo 'Connection Fail..'.$e->getMessage();
          }
        }
    
        public function select($sql){
          $stmt = $this->DBconnect->prepare($sql);
          $stmt->execute();
          return $stmt->fetchAll(PDO::FETCH_ASSOC);
        }
    
        public function insert($table,$data){
          $keys = implode(',', array_keys($data));
          $values = ":".implode(",:", array_keys($data));
    
          $sql = "INSERT INTO $table($keys) VALUES($values)";
          $stmt = $this->DBconnect->prepare($sql);
    
          foreach ($data as $key => $value) {
            $stmt->bindValue(":$key",$value);
          }
          return $stmt->execute(); 
    
    
        } 
        
        
    
        public function update($table,$data,$cond){
          $keys = '';
          foreach ($data as $key => $value) {
            $keys .= "$key=:$key,";
          }
          $keys = rtrim($keys,",");
    
          $sql = "UPDATE $table SET $keys WHERE $cond ";
          $stmt = $this->DBconnect->prepare($sql);
          foreach ($data as $key => $value) {
            $stmt->bindValue(":$key",$value);
          }
    
          return $stmt->execute(); 
        }
    
        public function delete($table,$cond,$limit=1){
          $sql = "DELETE FROM $table WHERE $cond LIMIT $limit ";
          return $this->DBconnect->exec($sql);
        }
    
        public function table_row_count($sql){
          $stmt = $this->DBconnect->prepare($sql);
          $stmt->execute();
          return $stmt->rowCount();
        }
    
        public function image_upload($getFile){
        $getExtention = explode('.', $getFile['name']);
        $getNewName = rand().'.'.$getExtention[1];
        $getDestination = './upload/'.$getNewName;
        move_uploaded_file($getFile['tmp_name'], $getDestination);
        return $getNewName;
        }
    
    
        
      }
    
    ?>
    
  • action.php

  • 
    
  • index.php

  • 
    
  • Database file sql

  • 
    
    --
    -- Database: `office_employee`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `tbl_employee_info`
    --
    
    CREATE TABLE `tbl_employee_info` (
      `id` int(11) NOT NULL,
      `image` varchar(255) NOT NULL,
      `name` varchar(255) NOT NULL,
      `designation` varchar(255) NOT NULL,
      `sex` varchar(255) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `tbl_employee_info`
    --
    
    INSERT INTO `tbl_employee_info` (`id`, `image`, `name`, `designation`, `sex`) VALUES
    (19, '6955.jpg', 'Roman Mondol', 'Teacher', '1'),
    (49, '31792.jpg', 'Programmer Rayhan', 'Software Engineer (JAVA and PHP)', '1'),
    (50, '12457.png', 'Aslam Khan', 'Telecommunication Enginner', '1'),
    (53, '11100.jpg', 'Cara Stevens', 'Software Engineer', '2');
    
    --
    -- Indexes for dumped tables
    --
    
    --
    -- Indexes for table `tbl_employee_info`
    --
    ALTER TABLE `tbl_employee_info`
      ADD PRIMARY KEY (`id`);
    
    --
    -- AUTO_INCREMENT for dumped tables
    --
    
    --
    -- AUTO_INCREMENT for table `tbl_employee_info`
    --
    ALTER TABLE `tbl_employee_info`
      MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=54;
    /*!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)