[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Add a Delete Confirmation

Posted on 2011-03-15
5
Medium Priority
?
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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 60

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 60

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

656 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