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
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. Edited by kicken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.