PHP Confirmation Box Before Delete Example

Mar 31, 2022 . Admin

Hello dev,

I am going to explain you How to PHP MySQL confirmation box before delete record using jquery ajax. You will learn How add confirmation box in php before deleting?. In side this article we will see PHP MySQL confirmation box before delete.

This article will give you simple example of Create confirmation alert before delete record with jQuery Ajax. We will use get simple How to show a confirmation message before delete.

I will give you simple Example of PHP Confirmation Box Before Delete.

So, let's see bellow solution:

    $servername = "localhost";
    $username = "root";
    $password = "root";
    $dbname = "aatman";

    $conn = new mysqli($servername,$username,$password,$dbname);

        die ('connection faild:'.$conn->connect_error);
<!DOCTYPE html>
    <link href="" rel="stylesheet" >
    <script src=""></script>
<body class="bg-dark">
    <div class="container mt-5">
        <div class="card">
            <div class="card-header">
                <h1 class="text-center">PHP Confirmation Box Before Delete Example</h1>
            <div class="card-body">
                <table class="table table-striped text-center">
                        <th width="100px">Action</th>
                        $sql = "SELECT * FROM users";
                        $result = $conn->query($sql);
                        while($row = $result->fetch_assoc()){
                    <tr id="<?php echo $row['id'] ?>">
                        <td><?php echo $row['username'] ?></td>
                        <td><?php echo $row['email'] ?></td>
                        <td><?php echo $row['mobile'] ?></td>
                        <td><button class="btn btn-danger btn-sm remove">Delete</button></td>
                    <?php } ?>
<script type="text/javascript">
        var id = $(this).parents("tr").attr("id");

        if(confirm('Are you sure to remove this record ?'))
                url: '/delete.php',
                type: 'GET',
                data: {id: id},
                error: function() {
                    alert('Something is wrong');
                success: function(data) {
                    console.log("Record removed successfully");  

          $sql = "DELETE FROM users WHERE id=".$_GET['id'];
         echo 'Deleted successfully.';

It will help you...