<?php
ini_set('display_errors', 1);
error_reporting(~0);
$con = mysqli_connect("localhost","root","abc456","ProudAsiaDB");
$sql = "SELECT * FROM cust001";
$users = mysqli_query($con,$sql);
?>

<html>
<head>
<title>ThaiCreate.Com PHP & MySQL (mysqli)</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>    
</head>

<body>
    <div class="container">
        <div class="row">
            <h3 class="text-center">Confirm before delete record</h3>
            <br>
            <table class="col-md-6 table table-bordered">
                <tr>
                    <th>Code</th>
                    <th>Name</th>
                </tr>
                <?php
                
                while($user = $users->fetch_assoc()) {
                ?>
                    <tr id="<?php echo $user['C_NO']; ?>">
                        <td><?php echo $user['C_NO']; ?></td>
                        <td><?php echo $user['C_NAME']; ?></td>
                        <td><button class="btn btn-danger remove-record">Delete</button></td>
                    </tr>
                <?php } ?>
            </table>
        </div>
    </div>
    <script type="text/javascript">
        $(".remove-record").click(function(){
            var id = $(this).parents("tr").attr("id");
            if(confirm('Are you sure to delete this record ?')) {
                $.ajax({
                    url: 'delete.php',
                    type: 'GET',
                    data: {id: id},
                    error: function() {
                      alert('Something is wrong, couldn\'t delete record');
                    },
                    success: function(data) {
                        $("#" + id).remove();
                        alert("Record delete successfully.");  
                    }
                });
            }
        });
    </script>
</body>
</html>