如何输入对话框到PHP

时间:2014-07-15 21:00:48

标签: javascript php

当用户想通过我的网页从数据库中删除一行时,我想提示一个消息框,询问“你确定要删除吗?”。然后在我的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";
}

?>

1 个答案:

答案 0 :(得分:0)

您只需将问题添加到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();
});