Solved

Add a Delete Confirmation

Posted on 2011-03-15
5
361 Views
Last Modified: 2012-05-11
This code presents data from a mysql database & displays it in a browser. The is a "Delete" option per record it pulls form the database. Is there a way for me to add some type of confirmation box that will pop up if I click the "Delete" link warning me that I am about to delete a record? I just don't want for users to mean to click on the "Edit" link & hit the "Delete" link by accident. Thanks
<table>
      <thead>
      <tr>
	   <table border='7'>

<th>PACTS No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Edit</th>
<th>Delete</th>
      </tr>      
      </thead>
      <tbody>
<?php
require('connection.php');

if (isset($_GET['op']) && $_GET['op'] == "d") 
if($_GET['op'] == "d" && !empty($_GET['id']) )
{
   $query="DELETE FROM `psrinfo` WHERE `fid`=" . $_GET['id'];
   $result = mysql_query($query) or die(mysql_error());  
}

$query="SELECT fid, pacts, fname, lname WHERE employee = 'employee1'";
$result = mysql_query($query) or die(mysql_error());  
 
while($row = mysql_fetch_array( $result )) {
?>
       <tr>
           
			<td><?php echo "".$row['pacts']; ?></td>
            <td><?php echo "".$row['fname']; ?></td>
            <td><?php echo "".$row['lname']; ?></td>
			<td><a href="edit.php?id=<?php echo $row['fid'];?>"><center>Edit</center></a></td>
            <td><a href="<?php echo $_SERVER['PHP_SELF'];?>?op=d&id=<?php echo $row['fid'];?>">Delete</a></td>
		    
      </tr>
<?php } ?>            
      </tbody> 
</table>

Open in new window

0
Comment
Question by:wantabe2
5 Comments
 
LVL 4

Expert Comment

by:GeoffHarper
ID: 35142068
<script type="text/javascript">
if( confirm("Delete record?") )
      alert("Delete record here");
else
      alert("Don't delete");
</script>
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35142247
Line 36 :
<td><a href="<?php echo $_SERVER['PHP_SELF'];?>?op=d&id=<?php echo $row['fid'];?>" onclick="return confirm('Delete record?');" >Delete</a></td>

Open in new window

0
 
LVL 51

Expert Comment

by:HainKurt
ID: 35142304
make your link like

<a href="<?php echo $_SERVER['PHP_SELF'];?>?op=d&id=<?php echo $row['fid'];?>" onclick="return confirm('sure?')">Delete</a>
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 35142317
ignore my post since it is already posted :)
0
 
LVL 3

Expert Comment

by:pius_babbun
ID: 35144755
Instead of this line just replace with the attched code and check if it is ok for you...

<a href="<?php echo $_SERVER['PHP_SELF'];?>?op=d&id=<?php echo $row['fid'];?>">Delete</a>

<a href="<?php echo $_SERVER['PHP_SELF'];?>?op=d&id=<?php echo $row['fid'];?>" onClick="javascript:if(confirm ('Are you having fun?')) return true; else return false;">Delete</a>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?op=d&id=<?php echo $row['fid'];?>" onClick="javascript:if(confirm ('Are you having fun?')) return true; else return false;">Delete</a>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now