问题
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