javascript - 在重定向之前如何提醒用户

标签 javascript php

我有一个函数可以获取用户的所有信息。在字符串的末尾,我为管理员提供了根据用户 ID 删除用户的选项。

我的字符串:

while ( $row = $result->fetch_assoc () ) {
   $string .= "<tr><td>" . $row ['id'] . "</td><td>" . $row ['first_name'] . "</td><td>" . $row ['last_name'] . "</td><td>" . $row ['email'] . "</td><td>" . $row ['role_name'] . "</td><td>[<a href='delete.php?id=" . $row ['id'] . "'>Delete</a>]</td></tr>";
}

我的删除页面:

if ($user->deleteUser($_GET['id']))
{
    header("Location: admin.php");
}
else
{
    echo "Could not delete the user!";
}

还有我的删除用户功能:

public function deleteUser($id)
{
    $sql = "DELETE FROM users WHERE id = ?";
    if (!$result = $this->db->mysqli->prepare($sql))
    {
        return false;
    }

    if (!$result->bind_param('i', $id))
    {
        return false;
    }

    return $result->execute();
}

所有这些都运行良好。

我想知道的是,我如何向管理员发出警报,说:“你确定吗?”例如。

最佳答案

使用confirm js函数:

<a href="delete.php?id=.." onclick="return confirm('are you sure?')">

关于javascript - 在重定向之前如何提醒用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22946382/

相关文章:

javascript - 通过浏览器中运行的 JavaScript 将数据推送到 Google 电子表格

javascript - 使用@font-face 时 SVG node.getBBox 不正确

javascript - 我如何以编程方式在 native react 中发送短信?

javascript - 哈希表与 JavaScript 中的对象

PHP - GetSQLValueString 函数

php - 创建将数据发送到数据库的 php 表单时出现问题

javascript - 根据鼠标坐标缩放 Canvas

php - Laravel 5.5 Redis + Socket.IO 无法工作

PHP/MYSQL 回显查询总数

php - 重复输入错误消息格式