This would be a fairly simple procedure. Personally I'm not sure its worth the effort for an admin area but hey we all have different opinions - so there is no right or wrong there.
Let's assume your delete buttons on your page are anchor tags and you have looped through your database of names to create the anchor tags. The dir value below has been inserted via the php loop through and is your record id.
<p><a href="#" class="delete" dir="1">Delete</a></p>
<p><a href="#" class="delete" dir="2">Delete</a></p>
<p><a href="#" class="delete" dir="3">Delete</a></p>
<p><a href="#" class="delete" dir="4">Delete</a></p>
When you click on the anchor tag (which has the class name 'delete') a lightbox opens. You also need to harvest the 'dir' value at the time the lightbox opens - which passes the record value to a hidden input field in the lighbox code.
<script>
$(document).ready(function() {
$('.delete').click(function(){
var record_id = $(this).attr('dir');
$('.record_id').val(record_id);
});
});
</script>
The 'dir' value gets passed to the lightbox in a hidden form field:
<input type="hidden" class="record_id" value="">
You have a delete button in the lightbox with the class of 'delete_record":
<p class="delete_record">Delete Record</p>
When the delete button in the lightbox is clicked the hidden form field value is harvested and passed to your delete_record.php page via the jquery/ajax script below, also housed on the same page.
<script>
$(document).ready(function() {
$('.delete_record').css('cursor','pointer').click(function(){
var record_id = $('.record_id').val();
;
$.ajax({
type: "POST",
url: "delete_record.php",
data: {
record_id: record_id
}
}).done(function() {
alert( "Record was deleted");
});
});
});
</script>
Your delete_record.php would look something like below, assuming you are using mysqli or if you are using mysql then you would follow the same delete procedure as normal.
<?php
$conn = new mysqli('localhost' , 'root' , 'root' , 'names');
if($conn->connect_errno) {
echo $conn->connect_error;
die('Sorry, cannot connect at moment, try later');
}
?>
<?php
// delete record
$record_id = $conn->real_escape_string(stripslashes(trim($_POST['record_id'])));
$conn->query("DELETE FROM names WHERE record_id = '$record_id'");
$record_deleted = "true";
?>
An alert box will pop up at the end confirming the record has been deleted. You do not have to deploy an ugly alert box - you can pass data back to the lightbox from the delete_record.php page in some nice fade in <div> if you want to be more subtle about it.