【问题标题】:Pop up alert yes/no , when using the answer to run PHP function使用答案运行 PHP 函数时弹出警报是/否
【发布时间】:2020-09-26 01:20:01
【问题描述】:

我想在 PHP throw onclick 按钮中运行删除写入的 SQL 函数。 我想过询问是/否弹出窗口将答案保存在变量中,如果variable==ok 运行SQL函数,有人可以帮我吗? 这是在 PHP 上编写的 SQL 查询:

function DeleteProduct($thisCatalog) {
    
    $connB = new ProductDAO();
    $connB->Connect();
    $pro_query = "DELETE * FROM Ikea WHERE `CatalogNumber` = $thisCatalog";
    $db_result = $connB->ExecSQL($pro_query);

    $html_result = 'Your Product Has Been Deleted! ';

    $connB->Disconnect();
    return $html_result;
}

这是删除按钮

<p align=center> <img src="pic/trash.png" title="Delete Product" onclick="conf();submit();">

delete 函数调用在哪里?

【问题讨论】:

  • 在第 132 行插入。剩下的代码在哪里?

标签: javascript php onclick popup dom-events


【解决方案1】:

我想这就是你想要的:

$(document).ready(function() {
    var answer = confirm("Delete?")
    if(answer) {
        $.ajax({
            url: "delete.php",
            type: "post",
            data: $('#yourForm').serialize(),
            error: function(data) {
                alert("There was an error while deleting from the database.");
            },
            success: function(data) {
                // do something
            });
        });
    }
    else {
        // do something
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-25
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 2011-05-02
    • 2020-09-06
    • 1970-01-01
    相关资源
    最近更新 更多