如何获得一个对话框的输入到php

How to get input of a dialog box to php

本文关键字:对话框 输入 php 一个 何获得      更新时间:2023-09-26

当用户想通过我的网页从数据库中删除一行时,我想提示一个消息框,询问"您确定要删除吗?"然后,在我的php代码中,我想跟踪用户是否按下了OkCancel,并执行如下所示的删除操作。我是一个新的网络编程和任何帮助将不胜感激。

<?php
.
.
.
if (user wants to delete a row from database) 
{
    echo "<script type='"text/javascript'"> confirm('"Are you sure you want to delete?'"); </script>";
    if(user press OK to delete")//How can I get input from the dialog box?
    {
        $deleterow = "DELETE FROM ElectronicShop WHERE WorkOrder = $i";
        $datadelete = sqlsrv_query($connectString, $deleterow) or die(print_r(sqlsrv_errors(SQLSRV_ERR_ALL), true));
        if($datadelete)
            echo "<br>you have deleted: $i Successfully";       
        else 
            echo "<br>could not be deleted: $i";
    }
    else
        echo "User pressed Cancel";
}
?>

您可以简单地将问题添加到onclick事件

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

或jquery

<a href=".." class="delete-confirm">...</a>
$(".delete-confirm").click(function(e) {
    if (!confirm("are you sure"))
        e.preventDefault();
});