Solved

Add a Delete Confirmation

Posted on 2011-03-15
5
360 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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 …
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

759 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

24 Experts available now in Live!

Get 1:1 Help Now