我正在建立登录系统,我想添加删除帐户的功能。我创建了代码,但是没有用。
require_once '../db.php';
session_start();
session_regenerate_id();
if (isset($_POST['delete'])) {
$username = mysqli_real_escape_string($connection, $_SESSION['username']);
$password = mysqli_real_escape_string($connection, $_SESSION['password']);
$result = $connection->query("DELETE FROM users WHERE username = '$username'");
$delete = mysqli_query($connection,$result);
if (!$delete) {
echo "Data Not Deleted";
} else {
echo "Data Deleted";
}
}
正在回显数据未删除。知道为什么它不起作用。
答案 0 :(得分:3)
尝试:
$result = "DELETE FROM users WHERE username = '$username'";
$delete = mysqli_query($connection,$result);
您正在查询中运行查询,否则...
答案 1 :(得分:0)
尝试$result = $connection->query("DELETE FROM users WHERE username = $username");
至少使用SELECT可以有效