简体   繁体   English

如果从数据库中单击“确定更新2”行,则发出警报,否则不执行任何操作

[英]Alert if click ok update 2 row from database else do nothing

i have a problem, i have a script that when i click a button it update data on database, but also display an alert. 我有一个问题,我有一个脚本,当我单击一个按钮时,它会更新数据库中的数据,但还会显示警报。 what im trying to do is, if i click "OK" on the alert it must update or insert (if there is no data) new data (on row statuscomanda and statuscomandatapiterii = "EXPEDIAT"). 我想做的是,如果我在警报上单击“确定”,它必须更新或插入(如果没有数据)新数据(在statuscomanda和statuscomandatapiterii =“ EXPEDIAT”行上)。 if i click cancel do nothing 如果我单击取消,则不执行任何操作

this is what i got, i got the connection to the database. 这就是我得到的,我得到了与数据库的连接。

<script>
function loaded()
{
if (confirm('A fost livrata comanda?')) { 
// Save it!
} else {
// Do nothing!
}
window.setTimeout(CloseMe, 200);
}

function CloseMe() 
{
window.close();
}
</script>

i have tryed this: 我已经尝试过:

<script>
function loaded()
{
if (confirm('A fost livrata comanda?')) <?php $sql = "UPDATE $table SET 
statuscomanda='expediat' statuscomandatapiterii='expediat' WHERE id=$id"; 
?> { 
// Save it!
} else {
// Do nothing!
}
window.setTimeout(CloseMe, 200);
}

function CloseMe() 
{
window.close();
}
</script>

i tought if i add this, it should do the job 我坚强如果我添加这个,它应该做的工作

if i click ok just update or add (if there is no data in the specific row) , the data updated should be "expediat" if i click cancel do nothing :) 如果我单击“确定”,则仅更新或添加(如果特定行中没有数据),则如果我单击“取消”,则更新的数据应为“ expediat” :)

EDITED!! EDITED!

i have tried this , 我已经尝试过了

function confirmDelete() {
    if (confirm('Doresti sa schimbi in expediat?')) {
        //Make ajax call
        $.ajax({
            url: "test2.php",
            type: "POST",
            data: {id : 5},
            dataType: "html", 
            success: function() {
                alert("A fost schimbat in expediat");
            }
        });

    }
}

used external php file nammed test2.php , that file change the data into database, but still not working if i press the yes button 使用了外部php文件nammed test2.php,该文件将数据更改为数据库,但是如果按“是”按钮仍然无法正常工作

First off PHP will always get executed before the page load, so in other words you can't call PHP from javascript functions. 首先,PHP将始终在页面加载之前执行,因此换句话说,您无法从JavaScript函数调用PHP。

That said you can call PHP routes from javascript functions using AJAX. 也就是说,您可以使用AJAX从javascript函数调用PHP路由。 Either that or you use javascript to submit a form to a php script. 或者,或者您使用javascript将表单提交到php脚本。

Those are really your 2 options. 这些确实是您的2个选择。

See this post: https://stackoverflow.com/a/19016091/6751133 看到这个帖子: https : //stackoverflow.com/a/19016091/6751133

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

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