?
Solved

Add a Delete Confirmation

Posted on 2011-03-15
5
Medium Priority
?
367 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 57

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 57

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
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.
Suggested Courses

777 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