Delete this-6ren">
gpt4 book ai didi

php - 删除按钮和确认

转载 作者:行者123 更新时间:2023-11-28 04:07:02 25 4
gpt4 key购买 nike

您好,我有一个工作链接可以从我的数据库中删除一行。

<a href="?action=delete&id=<? echo $id ?>" onclick="return confirm('Are you sure you want to delete?')"><strong>Delete this Case</strong></a></td>
<?php
if($_POST['action']=="delete")
{
$id = $_POST['id'];

mysql_query("DELETE FROM rmstable2 WHERE id= '$id'");
echo("> Case # $id has been deleted as requested. To see your changes please click <a href='/martinupdate.php?id=$id'>here</a></b><br>");
}
?>

我想要做的不是链接,而是我想要一个按钮,当按下它时它会弹出一个确认,然后如果为真则删除该行。
我不想意外删除。

<form>
<input type="button" value="Delete this Case" onclick="return confirm('Are you sure you want to delete?')";
<a href="?action=delete&id=<? echo $id ?>">
</form>

最佳答案

在你的文件的顶部试试这个:

<?php

if ($_SERVER['REQUEST_METHOD'] == 'DELETE' || ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['_METHOD'] == 'DELETE')) {
$id = (int) $_POST['id'];
$result = mysql_query('DELETE FROM rmstable2 WHERE id='.$id);
if ($result !== false) {
// there's no way to return a 200 response and show a different resource, so redirect instead. 303 means "see other page" and does not indicate that the resource has moved.
header('Location: http://fully-qualified-url/martinupdate.php?id='.$id, true, 303);
exit;
}
}

以此为形式:

<form method="POST" onsubmit="return confirm('Are you sure you want to delete this case?');">
<input type="hidden" name="_METHOD" value="DELETE">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<button type="submit">Delete Case</button>
</form>

关于php - 删除按钮和确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16962280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com