/* FB instanr*/

PHP AJAX CRUD using mysqli - Edit or update

Live Demo
PHP AJAX CRUD using mysqli - Edit or  update
Source Code
Hi, Every one In this post of update or change data CURD Application system by using PHP and Msqli With ajax Response without page refresh. you will learn how can you update or change data into Mysql Database table by using php procedural form programming method and You can learn how to update data into mysql database table without page refresh by using ajax response. So You can also check demo online even We have also provide demo link And source code download link with this tutorial. In this tutorial we have seen not only how can you update data from mysql Database even you can learn how to update row data by using Ajax Response Without page Refresh without page refresh PHP procedural form method. So our need to do this a form. we have use Bootstrap & Popeller table style classes for this task. then first time need to do this update data into mysql database table fetch single row of table and view our form fields. then our hidden field value if match this condition so update row's data other wish else to update. we view data of table row into same form insert table, it is most important and easy to update data same time. we used to do this functionality Ajax Response to fetch data from mysql database. we have seen not only how can you update dat into mysql table event our images file update into upload foler with our before image delete from upload folder by using php unlink function to do this. even we not use browser default alert, We use sweet alert for this powerfull user friendly alert. then so must load include bootstrap's css and js and Propeller's css and js files by using Download or CDN link for these files. this We have already create Database db_phpajax into table tbl_employee, no problem We have also provide sql file with source code or see please in this post. then do this and Fellow our video tutorial We have also provide youtube Video in this post. In next video tutorial we will task discussing on how to Delete rows' data into Mysql table in the same time delete image file from folder path by using PHP AJAX MySqli. So Dear, friend please share this my youtube video, subscribe my youtube channel and share this post 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

  • <?php 
      $connect = mysqli_connect("localhost","root","","db_phpajax");
      if (isset($_POST['id']) && $_POST['action'] == 'fetchSingle') {
        $output = '';
        $updateId = $_POST['id'];
        $query = "SELECT * FROM tbl_employee WHERE id='".$updateId."'";
        $data = mysqli_query($connect,$query);
        while ($row = mysqli_fetch_array($data)) {
          $output['first_name'] = $row['fName'];
          $output['last_name'] = $row['lName'];
          $output['designation'] = $row['designation'];
          $output['image_name'] = $row['image'];
          $output['hidden_image'] = '<img width="70px" height="70px" padding="20px" src="upload/'.$row['image'].'">';
    
        }
        echo json_encode($output);
      }
    ?>
  • 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'] == '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)