Jump to content

delete help


mdvignesh

Recommended Posts

 

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

 

I want a confirm box for delete

 

Help me solve..

 

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>  <button type="button" onClick="return show_confirm();">Delete</button>  </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."' ") or die(mysql_error());

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

<!--<form action="update.php" method="get">
<br />
Name:    <input name="name" type="text" maxlength="20" /><br /><br />

<input type="hidden" name="uno" value="// echo $id; ">

<input name="submit" type="submit" value="Save" />
</form>
-->
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.