美好的一天!
我想问一些问题。我有一个名为"删除"的链接在索引文件中。现在,我想在执行删除操作之前从用户确认。但是,我想将脚本确认为删除文件。我尝试了多种方式,但它没用。但它实际上可以删除,我的问题正是如此,确认框没有提示。还挺'在这里库存。请帮忙。继承我在index.php的代码(链接到删除):
`<p><strong>Country: </strong> <?php echo $country['countries'];?>   |
  <a href="editcountry.php?id=<?php echo $country['id']; ?>">Edit</a> |
<a href="deletecountry.php?id=<?php echo $country['id']; ?>"
class="confirmation">Delete</a></p>`
这是我的delete.php文件:
`<?php
require 'dbconnect.php';
$id = $_GET['id']; ?>
<script>
function confirmationDelete(){
var conf = confirm('Are you sure want to delete this record?');
if(conf==true){
<?php
$sql = "DELETE countries FROM countries WHERE id=$id";
if (mysqli_query($connect, $sql)) { ?>
alert("Record Deleted!");
<?php }
else { ?>
alert("Error Deleting Record!");
<?php } ?>
}
return conf;
}
</script>`
答案 0 :(得分:0)
在
<a href="deletecountry.php?id=1" onclick="return confirm('Are you sure you want to delete this record?')" class="confirmation">Delete</a>
然后在你的deletecountry.php
中<?php
session_start();
require 'dbconnect.php';
$id = $_GET['id']; ?>
$sql = "DELETE countries FROM countries WHERE id=$id";
if (mysqli_query($connect, $sql)) {
$_SESSION['msg'] = 'Successfully Deleted';
}
else {
$_SESSION['msg'] = 'Error Deleting';
}
// redirect to somewhereelse.php
然后在你的somewhereelse.php
<?php
session_start();
if(isset($_SESSION['msg']))
{
echo '<script>alert("'. $_SESSION['msg'] .'")</script>';
session_unset('msg');
}
?>
答案 1 :(得分:0)
<a onclick='javascript:confirmationDelete($(this));return false;' href="delete.php?id=1">Delete</a>
and create javascript function
function confirmationDelete(anchor)
{
var conf = confirm('Are you sure want to delete this record?');
if(conf)
window.location=anchor.attr("href");
}
or
<a href="delete.php?id=1" onClick=\"javascript:return confirm('are you sure you want to delete this?');\">delete</a>