php delete mysql row from link

…衆ロ難τιáo~ 提交于 2019-12-11 18:07:22

问题


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 #.

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>

回答1:


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>


来源:https://stackoverflow.com/questions/10792696/php-delete-mysql-row-from-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!