Jump to content

delete confirm box


mdvignesh

Recommended Posts

Hi!!

 

I want to delete record which i clicked the delete button in the table.

 

I want a confirm box for delete

 

Here is code display.php

 

<?php
$cn=mysql_connect("localhost","root","");
mysql_select_db("register",$cn);

$qry2=mysql_query("SELECT * FROM reg_table");
?>
<html>
<head>
<script type="text/javascript">

function show_confirm() {
var r=confirm("Do you want to Delete?");
if (r==true) {
  
  }
else {
  alert("You pressed Cancel!");
  }
}

</script>
</head>
<body>
<form action="delete.php" method="get">

<table width="200" border="1">
  <tr>
    <th scope="col">Name</th>
    <th scope="col">Address</th>
    <th scope="col">Gender</th>
    <th scope="col">Qualify</th>
  </tr>
<?php
while($res=mysql_fetch_array($qry2)) {
?>

  <tr>
    <td><?php echo $res['name']; ?></td>
    <td><?php echo $res['adrs']; ?></td>
    <td><?php echo $res['gender']; ?></td>
    <td><?php echo $res['qualify']; ?></td>
<td> <a href="edit.php?uid=<?php echo $res['id']; ?>">edit</a></td>

<td> <input type="hidden" name="nid" value="<?php echo $res['id']; ?>" /> </td>    
    <td> <input type="submit" value="Delete" name="del" onClick="return show_confirm();">
    </td>

  </tr>
<?php
}
?>

</table>
</form>

</body>
</html>

 

delete.php

 

<html>
<body>
<?php

$cn=mysql_connect("localhost","root","");
mysql_select_db("register",$cn);

$del_id=$_GET['nid'];
$qry=mysql_query("delete from reg_table where id='".$del_id."' ");

if($qry) {
echo "deleted";
}
else {
echo "not deleted";
}
?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/255107-delete-confirm-box/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.