当使用答案运行PHP函数时,会弹出是/否警报

Pop up alert yes/no , when using the answer to run PHP function

本文关键字:答案 运行 PHP 函数      更新时间:2023-09-26

我想运行一个SQL函数,在PHP中删除写并抛出onclick按钮。我考虑过询问是/否弹出窗口,将答案保存在变量中,如果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();">

删除函数调用放在哪里?

我想这就是你想要的:

$(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
    }
});