drcrc28428
drcrc28428
2018-09-05 18:42

使用PHP删除MySQL数据库前的确认[复制]

已采纳

This question already has an answer here:

I have a button which deletes a MySQL database. It works great, but I just would like to have a confirmation before doing so.

button HTML

<form action="delete.php" method="post">
    <input type="submit" name="someAction" value="Delete all database" />
</form>

delete.php

<?php
$servername = "server";
$username = "user";
$password = "";
$dbname = "testdb";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// sql to delete a record
$sql = "DELETE FROM exampledb";

if ($conn->query($sql) === TRUE) {
    echo "Record deleted successfully";
} else {
    echo "Error deleting record: " . $conn->error;
}

$conn->close();
?>
</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dpps0715 dpps0715 3年前

    you can use the confirm() function ....

     <form action="delete.php" method="post"  onSubmit="return confirm('Are you sure to delete?')">
         <input type="submit" name="someAction" value="Delete all database" />
     </form>
    
    点赞 评论 复制链接分享