nethken nethken - 1 year ago 116
jQuery Question

PHP - Delete via confirmation with bootstrap

This is what i want to do i will give you a scenario. If i click the delete button the modal will pop up and ask if you want to delete or not. After clicking ok it will perform the query and delete it to database. Can someone give me ideas how to do it?

this is the picture of my grid.
enter image description here

here is my code.

<!DOCTYPE html>
<link rel="stylesheet" href ="css/bootstrap.min.css">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">

<div class="container">
<table class="table table-bordered">
<th width="60">ID</th>
<th width="200">Title</th>
<th width="150">Date Posted</th>
<th width="200">Image</th>
<th width="200">Action</th>

$stmt = mysqli_prepare($con, "SELECT * FROM news ORDER BY news_id");
$result = mysqli_stmt_get_result($stmt);
while($row = mysqli_fetch_array($result)){
<td><?php echo $row['news_id']; ?></td>
<td><?php echo $row['news_title']; ?></td>
<td><?php echo $row['news_date']; ?></td>
<td><?php echo $row['news_content']; ?></td>
<td><img style="height:150px; width:200px;" src="<?php echo $row['news_image']; ?>" ></td>
<a href="edit2.php?newsid=<?php echo $row['news_id'];?>" class='btn btn-info left-margin'><span class="glyphicon glyphicon-edit"></span> Edit</a>
<a class='btn btn-danger delete-object'><span class="glyphicon glyphicon-remove"></span> Delete</a>

<script src="js/jquery-1.12.4.min.js"></script>
<script src="js/bootstrap.min.js"></script>


Answer Source

You can use Bootstrap dialogs for showing dialogs. When showing a confirmation dialog, you can check if user clicked OK, then do an AJAX request to ex: list.php?delete_photo=31

BootstrapDialog.confirm('Hi Apple, are you sure?', function(result){
            if(result) {
            }else {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download