我在php中有一个表,该表显示数据库中表的数据:用户名,电子邮件等,并且我还添加了删除选项。删除选项可以正常工作,并在删除之前显示确认消息。但是,当用户单击删除选项时,我想添加一条带有所需密码的确认消息。
每次我按下Delete(删除)选项时,都会出现一条确认消息以删除我想要的数据,但是我希望确认消息具有密码来完全删除该消息。我希望您显示一条消息类型:confirm ('Please confirm deletion and enter the password to delete');
。
有人知道怎么做吗?谢谢。
这就是我所拥有的:
index.php:
<table>
<tr>
<th colspan="3"><h2>Users</h2></th>
</tr>
<tr>
<th> Name </th>
<th> Email </th>
<th> Delete</th>
</tr>
<?php
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
if ($result->num_rows==0){
echo "No users";
}else{
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["username"]."</td><td>".$row["email"]."</td><td><a class='eliminate' onClick=\"javascript: return confirm('Please confirm deletion');\" href=\"delete.php?id=".$row['id']."\">X</a></td></tr>";
}
}
?>
</table>
delete.php:
<?php
include('Conexion.php');// Check connection with DB
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id = $_GET['id']; // $id is defined
mysqli_query($conn,"DELETE FROM users WHERE id='".$id."'");
mysqli_close($conn);
header("Location: index.php");
?>
我当时正在考虑引入这样的脚本:
<script>
function myFunction() {
var txt;
var password = prompt("Please confirm deletion and enter the password to delete:", "Password");
if (password == null || password == "" || password != "realpassword") {
txt = "User cancelled the prompt.";
} else {
txt = "Are you sure?";
}
document.getElementById("demo").innerHTML = txt;
}
</script>