如何使用PHP更新和删除同一页面中的MySQL记录

I need to update & delete data in the same page.

My problem is how to get the update or delete record id in the same page while the user clicks the "update" or "delete" link.

Anyone please help how to update and delete records in same page.

Please find my code below (View.php)

View.php

<?php
$q =($_GET['q']);
if($q=="all")
{
    $result=mysql_query("select * from password");
}
else
{
$result=mysql_query("select * from password WHERE tag = '".$q."'");
}
if($result === false )
{
    die(mysql_error());
}
?>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>username</th>
<th>Password</th>
<th>Account Type</th>
<th>Link</th>
<th>update</th>
<th>Delete</th>
</tr>
</thead>
<?php

while($row=mysql_fetch_array($result))
{
    $id=$row['id'];
     $name=$row['name'];
    $url=$row['url'];
    $uname=$row['username'];
    $pass=$row['password'];
    $tag=$row['tag'];
    $des=$row['description'];

    ?>
    <tbody>
    <tr>
    <td><?php echo $id; ?></td>
    <td><?php echo $name; ?></td>
    <td><?php echo $uname; ?></td>
    <td><span data-tooltip aria-haspopup="true" class="has-tip" title="<?php echo $pass; ?>">View</span></td>
    <td><?php echo $des; ?></td>
    <td><a href="<?php echo $url; ?>" title="<?php echo $name; ?>" target="_blank">Link</a></td>
    <td><a href="update.php?<?php echo $id; ?>">Update</a></td>
    <td><a href="delete.php?<?php echo $id; ?>">Delete</a></td>
    </tr>
    </tbody>
    <?php

}

?>
</table>

By clicking a link you should send back some information to the server. This can happen via POST, GET (not recommended) or AJAX if you want to create an interactive look an feel.

In your code you are using two different file to to update and delete your records.

Example : update.php and delete.php and you are sending the id in parameter.

If you want to keep same page for both then create a page named with action.php and send one more parameter along with id.

Like : update.php?id=<?php echo $id; ?>&type=update/delete

you can keep any name for action.php page that was only for example.

Note : Also keep in mind about @patrick comment.

try it as i have
(sample.php)

//db connections..
if ($_GET['delete_id']!="")
{
//delete statement goes here....
}
$result = mysql_query("SELECT commentid FROM comments") 
or die(mysql_error());  

while($row = mysql_fetch_array( $result )) {
?>
    <a href="sample.php?delete_id=<?=$row['id']?>">delete</a>
<?php } ?>