Jump to content

Delete Confirmation in PHP


john666

Recommended Posts

i have Links like

 

View | Update | Delete | Opreation for student  Record on Student ID base

 

On Delete link there is a Page name Std_delete.php

and here is its Code

-----------------------------

<?php
$id=$_REQUEST['student_id'];
if($id)
{
 
include('config.php');
if ($id) {
mysql_query("delete from student where std_id=$id");
header("Location:classes.php");
}
}
 
 
?>
 
 
But i want that when Some 1 try to delete Record its first ask from USer ..Do you Want to delete Reocrd should run a javascript Code How and where i have to add that Code ???
Link to comment
https://forums.phpfreaks.com/topic/283807-delete-confirmation-in-php/
Share on other sites

A quick and dirty method is to just use onclick and confirm():

<a href="std_delete.php?student_id=12345" onclick="return confirm('Do you really want to delete this student?');">Delete</a>
A better but more involved method would be to use a modal dialog such as jQuery UI's dialog to prompt the user, then send a POST via ajax to delete the item if confirmed.

<a href="std_delete.php?student_id=12345" class="delete-link">Delete</a>
<script type="text/javascript">
$('.delete-link').click(function(e){
  $('<div>').text('Do you really want to delete this student?').dialog({
    modal: true
    , buttons: {
      "Yes": function(){
        $.post(e.target.href);
      }
    }
  }
});
</script>
The above is just a rough outline of the code, not a functional example. Check the documentation for jQuery and jQuery UI and you can finish it up.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.