使用PHP删除MySQL数据库之前的确认

时间:2018-09-05 18:42:31

标签: php html mysql

我有一个删除MySQL数据库的按钮。效果很好,但我只是想先确认一下。

按钮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();
?>

1 个答案:

答案 0 :(得分:0)

您可以使用confirm()函数...。

 <form action="delete.php" method="post"  onSubmit="return confirm('Are you sure to delete?')">
     <input type="submit" name="someAction" value="Delete all database" />
 </form>