Jump to content

'Are you sure you want to delete this record' page, any suggestions?


bossman

Recommended Posts

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

 

 

Link to comment
Share on other sites

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');

?>

Link to comment
Share on other sites

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()">

 

 

 

Link to comment
Share on other sites

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.

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.