php从链接中删除mysql行 [英] php delete mysql row from link

查看:26
本文介绍了php从链接中删除mysql行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个动态链接,让用户根据行 ID # 从 mysql 数据库中删除一行.

I am trying to create a dynamic link that will let the user delete a row from a mysql database based on the rows ID #.

我还尝试输入一些 javascript 确认信息,表明用户确实想删除相关行.

I am also trying to input some javascript confirmation that the user really wants to delete the row in question.

我的问题是如何做到这一点?我有一些想法...(见下文)我在正确的轨道上吗?

My question is how to accomplish this? I have some ideas...(see below) am I on the right track?

<head>
    <?php
        require 'include/episodelist.db.php';
        mysql_query("DELETE FROM season WHERE ID='$id'");

        mysql_close();
    ?> 
    <script type="text/javascript">
        function confSubmit(form) {
            if (confirm("Delete this record?")) {
                form.submit();
            } else {
            }
        }
    </script>
</head>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
    <input type="button" onClick="confSubmit(this.form);" value="Delete">
</form>

推荐答案

我可以告诉你如何做到这一点的基本想法.只需为每一行创建一个链接,将控件重定向到 delete.php(将执行删除的文件.)只有在您的用户确认删除操作的情况下,控件才会被重定向.链接可以是这样的.

I can give you the basic idea how you can do this. Just create a link for each row which will redirect the control to delete.php(The file which will perform the deletion.) The control will only be redirect in case your user confirm the deletion operation. The link can be like this.

 <a class="button" href="<?php echo base_url();?>delete.php/<?php echo $row->id;?>" onclick="javascript: return confirm('Are you SURE you wish to do this?');">Delete</a>

这篇关于php从链接中删除mysql行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆