0

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

4
Contributors
5
Replies
11
Views
7 Years
Discussion Span
Last Post by Samuz
1

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>
Votes + Comments
Thank You
1

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>
Votes + Comments
great user, above and beyond the call
0

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.

0

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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.