删除按钮和确认 [英] Delete button and confirmation
本文介绍了删除按钮和确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我有一个工作链接从我的数据库中删除一行。
< a href =?action = delete& id =< ;? echo $ id?> ')>< strong>删除此案例< / strong>< / a>< / td> onclick =return confirm('您确定要删除吗?
<?php
if($ _ POST ['action'] ==delete)
{
$ id = $ _POST ['id'];
mysql_query(DELETE FROM rmstable2 WHERE id ='$ id');
echo(> Case#$ id已被删除,要查看您的更改,请点击< a href ='/ martinupdate.php?id = $ id'> here< / a>< / b个;<峰; br>中);
}
?>
我正在寻找的是一个链接,而不是我想要的按钮它带来了一个确认,然后删除该行如果是true。
我不希望意外删除。
<形式>
< input type =buttonvalue =删除此案例onclick =return confirm('您确定要删除?');
< 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){
//无法返回200响应并显示不同的资源,因此重定向。 303表示看到其他页面,并不表示资源已经移动。
header('Location:http://fully-qualified-url/martinupdate.php?id ='。$ id,true,303);
出口;
$ b 以这种形式:
< form method =POSTonsubmit =return confirm('您确定要删除此案例吗?');>
< input type =hiddenname =_ METHODvalue =DELETE>
< input type =hiddenname =idvalue =<?php echo $ id;?>>
< button type =submit>删除个案< / button>
< / form>
Hi I have a working link to delete a row from my database.
<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>");
}
?>
what I am looking to do is instead of having a link I want to have a button that when pressed it brings up a confirmation and then deletes the row if true.
I do not want accidental deletions.
<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>
解决方案 Try this at the top of your file:
<?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;
}
}
With this as the form:
<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>
这篇关于删除按钮和确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文