简体   繁体   English

php从链接中删除mysql行

[英]php delete mysql row from link

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 #. 我正在尝试创建一个动态链接,让用户根据行ID#从mysql数据库中删除一行。

I am also trying to input some javascript confirmation that the user really wants to delete the row in question. 我也试图输入一些javascript确认,用户确实想要删除有问题的行。

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>

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. 只需为每一行创建一个链接,该链接将控件重定向到delete.php(将执行删除的文件。)只有在用户确认删除操作时,控件才会重定向。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM