简体   繁体   English

如何获取对话框输入到PHP

[英]How to get input of a dialog box to php

When a user wants to delete a row from a database via my webpage, I want to prompt a message-box asking, "Are you sure you want to delete?". 当用户想要通过我的网页从数据库中删除一行时,我想提示一个消息框,询问“您确定要删除吗?”。 Then in my php code, I want to track if the user press Ok or Cancel and execute the delete operation as shown bellow. 然后在我的PHP代码中,我想跟踪用户是否按“ Ok或“ Cancel并执行删除操作,如下所示。 I am new to web-programming and any help would be appreciated. 我是网络编程的新手,我们将不胜感激。

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

?>

You can simply add the question to your onclick event 您只需将问题添加到onclick事件中

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

or with jquery 或与jQuery

<a href=".." class="delete-confirm">...</a>

$(".delete-confirm").click(function(e) {
    if (!confirm("are you sure"))
        e.preventDefault();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM