How to Delete Record from MySQL Table with AJAX

How-to-Delete-Record-from-MySQL-Table-with-AJAX

You can do this with jQuery AJAX where you need to pass the record id from AJAX which needs to delete. your page is not a load. AJAX is not a page load.

This Code use for your record file.

<?php
 $(function() {
 $(".delete").click(function(){
 var element = $(this);
 var del_id = element.attr("id");
 var info = 'id=' + del_id;
  $.ajax({
    type: "POST",
    url: "delete_job.php",
    data: info,
    success: function(){
      swal({
    title: 'Are you sure?',
    text: "You won't be able to revert this!",
    type: 'success',
    confirmButtonColor: '#3085d6',
    confirmButtonText: 'Ok'
  }).then(function () {
   window.location.assign('view_job.php');
  });
  }
 });
   $(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
   .animate({ opacity: "hide" }, "slow");
 return false;
 });
});
?>

You are create a one Dalete.php file than after you are add this code.
<?php
include("config.php");
session_start();

if($_POST['id'])
{
 $id=mysqli_real_escape_string($connection, $_POST['id']);
 $delete = "DELETE FROM `post_job` WHERE id='$id'";
 mysqli_query($connection, $delete);
}
?>

This code your button code and use for button is your all record show.

<a  data-id="<?php echo $row['id'];?>" id="<?php echo $row['id'];?>" class="btn btn-theme btn-xs btn-default delete">Remove</a></td>
We Well organized and easy-to-understand Interactive tutorials With lots of examples of how to use Tutorials WordPress, PHP, Bootstrap, Bootstrap 4, HTML, CSS, AJAX, jQuery, Woocommerce, Post, Database, Javascript, Theme, Responsive, Templates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact us

Fill in the form below or give us a call and we'll contact you. We endeavour to answer all enquiries within 24 hours on business days.