I was wondering if anybody would be able to help me insert a confirm delete popup window that closes after submit.

here is what i have so far
index.php

}
//delete tool button actions
if (isset($_GET['deletetool']))
{
 $id = mysqli_real_escape_string($link, $_POST['id']);
 $sql = "DELETE FROM tools WHERE id='$id'";
 if (!mysqli_query($link, $sql))
 {
   $error = 'Error deleting tool: ' . mysqli_error($link);
   include 'error.php';
   exit();
 }

 header('Location: .');
 exit();
}

maintool.php

<!--Delete Tool-->
 <div valign="bottom"><form action="?deletetool" method="post">
     <input type="hidden" name="id" value="<?php
       echo $tools['id']; ?>"/>
     <br><div><input type="submit" value="Delete"></div>
 </form></div></td>
 </table>

Any help would be greatly appreciated

Recommended Answers

All 5 Replies

You could try this. the javascript command is added to the submit

<!--Delete Tool-->
 <div valign="bottom"><form action="?deletetool" method="post">
     <input type="hidden" name="id" value="<?php
       echo $tools['id']; ?>"/>
     <br><div><input type="submit" value="Delete" onClick="return confirm('Are you sure you want to delete?')"></div>
 </form></div></td>
 </table>
commented: Thank You +0

Thank You! I was struggling with that

This is confirmation part, hope you will be able to write delete part using necessary HTML and PHP as well.

<html>
<head>
<script type="text/javascript">
<!--
function confirmation(){
var answer = confirm('Are you sure you want to delete?');
if(answer){
form1.submit();
}
else{
alert("Cancelled the delete!")
}
}
//-->
</script>
</head>
<body>
<form name="form1" method="post" action="delete.php">
<input type="button" value="Delete" onClick="confirmation();">
</form>
</body>
</html>
commented: great user, above and beyond the call +1

ya i got it i thank you guys both. I'll rate you guys as + no worries. Its great to find help for aspiring users, like myself.

Hi guys, I did this but when I hit cancel it still deletes anyway. Here's my code:

<script type="text/javascript">
<!--
function confirmation(){
var answer = confirm('Are you sure you want to delete?');
if(answer){
form1.submit();
}
else{
alert("Cancelled the delete!")
}
}
//-->
</script>
<form name="form1" method="post" action="">
  <table width="918" border="1">
    <tr>
      <td>TS1</td>
      <td>Rulername</td>
      <td>Nation id</td>
      <td>Select</td>
    </tr>
    <?php
$query="SELECT * FROM TS1";
$result=mysql_query($query);
$sno=1;
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
?>
    <tr>
      <td><? echo $sno;?></td>
      <td><? echo $row['ruler'];?></td>
      <td><? echo $row['nation_id'];?></td>
      <td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['nation_id']; ?>"></td>
    </tr>
	<?
	$sno=$sno+1;
	}
	?>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td colspan="2"><div align="center">
        <input name="delete" type="submit" id="delete" value="Delete Records" onClick="confirmation();">
      </div></td>
    </tr>
  </table>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.