bossman Posted August 31, 2009 Share Posted August 31, 2009 I built an admin console for a project management site, you can add a project (title, link to project, etc..), edit an existing project, or delete projects. But upon running through it a few times, i realized, a user can simply delete an entry and PUFF....it's gone, no prompt to ask, 'are you sure you want to delete this record?' ....i realized that something like this will be necessary, so my question... from the view projects page, there is a list of the projects and underneath i have the links, add/edit/delete.... from there it goes to a delete_process.php page that has the functions to delete... ...am i going to have to pass the variables from the first page, then to the confirm delete page, and THEN to the actuall process page, or is there a more simple and easier way to do this? perhaps javascript pop up or something? THANKS bossman Quote Link to comment https://forums.phpfreaks.com/topic/172606-are-you-sure-you-want-to-delete-this-record-page-any-suggestions/ Share on other sites More sharing options...
bossman Posted August 31, 2009 Author Share Posted August 31, 2009 perhaps i should post the code to the delete_process.php page.. its passing the id through the variable with delete_id <? include ("inc/db_connect.php"); //store the info passed from the view all records page... $delid = $_GET['delete_id']; //open connection to server and DB... $link = mysql_connect ($h, $u, $p) or die ("Could not connect to database, try again later"); mysql_select_db($d, $link); //create a SQL query and run it... $query = "DELETE FROM `projects` WHERE project_id = $delid"; $result = mysql_query($query); //add troubleshooting statements we'll comment out later... //print $query; //echo ($result) ? "\r\n successful \r\n":"\r\n NOT successful \r\n"; //close connection... mysql_close($link); //redirect back to view all records... header('Location:admin_viewby_all.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/172606-are-you-sure-you-want-to-delete-this-record-page-any-suggestions/#findComment-909855 Share on other sites More sharing options...
jake2891 Posted August 31, 2009 Share Posted August 31, 2009 yeah it can be done easily in javascript if you want to use js. function Testconfirm() { var chk=confirm("Are you sure you wish to delete this record?"); if (chk) return true ; else return false ; } <input type="Submit" onClick="return Testconfirm()"> Quote Link to comment https://forums.phpfreaks.com/topic/172606-are-you-sure-you-want-to-delete-this-record-page-any-suggestions/#findComment-909859 Share on other sites More sharing options...
kingnutter Posted August 31, 2009 Share Posted August 31, 2009 I've been using a simple bit of HTML for this: <a href="delete_record.php?id=<?php echo $row->record_id; ?>" onclick="return confirm('Are you sure you want to delete <?php echo $row->record_name; ?>?')">delete</a></font> Delete_record is actually a page that performs a MySQL query that does the deletion so this is quite safe. Quote Link to comment https://forums.phpfreaks.com/topic/172606-are-you-sure-you-want-to-delete-this-record-page-any-suggestions/#findComment-909862 Share on other sites More sharing options...
mikesta707 Posted August 31, 2009 Share Posted August 31, 2009 Be aware that javascript can be disabled by the client. This may not matter to you much, but you may want to take some extra precautions to make sure data doesn't get deleted accidently Quote Link to comment https://forums.phpfreaks.com/topic/172606-are-you-sure-you-want-to-delete-this-record-page-any-suggestions/#findComment-909863 Share on other sites More sharing options...
bossman Posted August 31, 2009 Author Share Posted August 31, 2009 all the code you guys provided was for form submissions, in my admin, the [delete] button is simple just an <a href="#">Delete</a>....for that, would i use the same javascrpit, except use onclick instead?? Quote Link to comment https://forums.phpfreaks.com/topic/172606-are-you-sure-you-want-to-delete-this-record-page-any-suggestions/#findComment-909876 Share on other sites More sharing options...
mikesta707 Posted August 31, 2009 Share Posted August 31, 2009 yeah you would simply use on click and have it return true of false Quote Link to comment https://forums.phpfreaks.com/topic/172606-are-you-sure-you-want-to-delete-this-record-page-any-suggestions/#findComment-909877 Share on other sites More sharing options...
bossman Posted August 31, 2009 Author Share Posted August 31, 2009 that worked!! thanks a lot guys i appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/172606-are-you-sure-you-want-to-delete-this-record-page-any-suggestions/#findComment-909883 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.