Jump to content

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


Navajo

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();
}

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.