无法找到未从数据库中删除数据的原因

时间:2018-08-21 15:42:08

标签: php mysql

我正在建立登录系统,我想添加删除帐户的功能。我创建了代码,但是没有用。

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

正在回显数据未删除。知道为什么它不起作用。

2 个答案:

答案 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可以有效