Navajo Posted February 25, 2009 Share Posted February 25, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/146832-solved-how-to-do-an-are-you-sure-you-want-to-delete-this-box/ Share on other sites More sharing options...
JonnoTheDev Posted February 25, 2009 Share Posted February 25, 2009 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/146832-solved-how-to-do-an-are-you-sure-you-want-to-delete-this-box/#findComment-770875 Share on other sites More sharing options...
Navajo Posted February 25, 2009 Author Share Posted February 25, 2009 sorted thanks very much! Quote Link to comment https://forums.phpfreaks.com/topic/146832-solved-how-to-do-an-are-you-sure-you-want-to-delete-this-box/#findComment-770892 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.