aron pascua aron pascua - 4 months ago 6x
jQuery Question

How to modal in PHP with delete confirmation

I'm trying to add a modal in my system that when you click it a modal will appear and ask you a confirmation if you want to delete that certain data.

But in my present code, when you click the button, it will direct you to a blank page without modal. The

is passing correctly but how can I output the modal?

Here's my code for PHP:


while(mysqli_stmt_fetch($stmt)) {
echo "<tr>";
echo "<td class=\"col-md-2\" onclick=\"document.location = 'modal_delete.php?id=$id';\"><button type=\"button\" class=\"btn btn-primary btn-md\" data-toggle=\"modal\" data-target=\"#myModal\">Delete</button></td>";
echo '</tr>';


Here is the code for the modal (modal_delete.php):


include '../session.php';
include 'header.php';


<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
<div class="modal-body">
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Delete</button>

I hope guys you help me. Thank you


On modal_delete.php you need to trigger the modal using javascript after the DOM is ready.

  $(function () {