wantabe2
asked on
Add a Delete Confirmation
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
make your link like
<a href="<?php echo $_SERVER['PHP_SELF'];?>?op =d&id=<?ph p echo $row['fid'];?>" onclick="return confirm('sure?')">Delete</ a>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?op
ignore my post since it is already posted :)
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=<?ph p echo $row['fid'];?>">Delete</a>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?op =d&id=<?ph p echo $row['fid'];?>" onClick="javascript:if(con firm ('Are you having fun?')) return true; else return false;">Delete</a>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?op
<a href="<?php echo $_SERVER['PHP_SELF'];?>?op
<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>
if( confirm("Delete record?") )
alert("Delete record here");
else
alert("Don't delete");
</script>