gpt4 book ai didi

PHP 从数据库中删除项目不起作用

转载 作者:行者123 更新时间:2023-11-29 04:39:48 25 4
gpt4 key购买 nike

我有一个小脚本可以通过 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>";

这在远程主机上有问题,但在我的本地服务器上没有。

最佳答案

试试这个

<?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");
}
?>

关于PHP 从数据库中删除项目不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32289531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com