douhu1990 2015-08-04 10:18
浏览 124

在通过onclick删除数据库传递变量中的数据之前确认

echo '<td><a href="delete.php?id='.$id.'"><img src="img/delete.png" width=20px height=20px name="delete"></a></td></tr>';

this is my img icon. whenever you click it, it will navigate you to a new page where the deletion happens.

echo "<script>window.confirm('Delete?')</script>";

$id=$_GET['id'];

$query = "UPDATE `main` SET status=0 where id = $id";
$sql = $db->prepare($query);
if ($sql->execute()) {
    echo "<script>
            window.location='view.php';
        </script>";
}
?>
</body>
<script type="text/javascript" src="./static/dist/js/main.js"></script>
</html>

this is delete.php. but i need to check first if the window.confirm is true before doing the deletion. but i don't know how

  • 写回答

2条回答 默认 最新

  • duanfei1930 2015-08-04 10:26
    关注

    Instead put the confirm() in the link of image before navigating to another page

    echo '<td><a href="delete.php?id='.$id.'" onclick="return confirm(\'Delete?\')"><img src="img/delete.png" width=20px height=20px name="delete"></a></td></tr>';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入