Jump to content

[SOLVED] How to do an "are you sure you want to delete this?" box


Recommended Posts

Hey all,

 

I have a delete button within a html table, and when delete is clicked I was it to come up with a warning box saying "Are you sure you want to delete this record?" the user would click "ok" to delete or "cancel" to cancel the request.

 

This is my code for the button:

 

echo "<td align=center><form name=\"passDelete\" method=\"get\" action=\"passDelete.php?id=$productID\"><input type=\"hidden\" name=\"ModuleCode\" value=\"$productID\"><input type=\"submit\" name=\"submit\" value=\"Delete\"></form></tr>\n";

 

The slashes are because its within a html table, which took me ages to get right lol.

 

Any help?

 

Thanks in advance to anyone who helps!

Firstly you need a javascript function

function decision(message, url){
if(confirm(message)) location.href = url;
}

 

Use an image or whatever as the delete button and call the function:

 

<a href='#'><image border='0' src='images/trash.gif' onclick="decision('Are you sure?','mypage.php?action=delete&id=2')"></a>

 

Then add your php to delete the record

if($_GET['action'] == 'delete') {
  mysql_query("DELETE FROM table WHERE id='".$_GET['id']."'");
  header("Location:mypage.php");
  exit();
}

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.