删除按钮删除数据库行 [英] Delete button which deletes database row
问题描述
我刚刚做了一个php函数
I just made a php function
function deletebooking($orderID){
$sql="DELETE FROM bs_reservations WHERE id='".$orderID."'";
$result=mysql_query($sql) or die("oopsy, error when tryin to delete events 2");
}
我有一个.php文件,该文件处理提交的表单,然后显示HTML页面.我如何添加一个删除预订按钮,该按钮将上述功能调用到HTML页面.$ orderID变量已经设置.
I have a .php file which process a submitted form and then displays a HTML page. How do i add a delete booking button which calls the above function to the HTML page. The $orderID variable is already set.
建议
推荐答案
您可以在单击的按钮上使用javascript代码以删除记录
You can use a javascript code on the button which you click to delete the record as
<input type="button" name-"abc" id="abc" onclick="return Deleteqry(<?php echo $orderID ?>);"/>
现在,您可以将< head></head>
内的javascript函数编写为
Now you can write the javascript function inside the <head></head>
as
function Deleteqry(id)
{
if(confirm("Are you sure you want to delete this row?")==true)
window.location="yourpagename.php?del="+id;
return false;
}
现在您可以在页面顶部写为
Now you can write on the top of your page as
if($_GET['del'])
{
deletebooking($orderID);
}
在这里,我们正在使用消息警报,通过javascript警报框来确认删除的内容...
Here we are using a message alert for the conformation of the deletion using the javascript alert box...
这篇关于删除按钮删除数据库行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!