我有一个小脚本,用于从我的数据库中删除id号的证书,但这不能正常工作。
<?php
session_start();
include("config.php");
if(isset($_SESSION['username'])){
$conn = mysqli_connect(host, db_user, db_pass, db);
$id = htmlspecialchars($_GET['id']);
$query = "DELETE FROM cert_details where certid = ". mysql_real_escape_string($id);
$r = mysqli_query($conn, $query);
mysqli_close($conn);
header('location: dashboard.php');
}
else{
header("location: index.php");
} ?>
这就是我在HTML端做的事情
echo "<form method=\"POST\" action=\"deletecert.php?id=$certidd\" onSubmit=\"return confirm('Are you sure?')\">";
echo "<button name=\"del\" value=\"Delete\" type=\"submit\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-trash\"></i></button>";
echo "</form>";
这在远程主机上有问题,但在我的本地服务器上没有。
答案 0 :(得分:4)
试试这个
<?php
session_start();
require "./config.php";
if (isset($_SESSION['username'])) {
$mysqli = new mysqli(host, db_user, db_pass, db);
/* check connection */
if ($mysqli->connect_errno) {
die("Connect failed: %s\n", $mysqli->connect_error);
}
$id = htmlspecialchars($_GET['id']);
$mysqli->query("DELETE FROM cert_details where certid = ". $mysqli->real_escape_string($id));
mysqli->close();
header('location: ./dashboard.php');
}else{
header("location: ./index.php");
}
?>