<a href=""> Action to database

时间:2015-11-17 15:46:05

标签: php wordpress

Is there a way to update a database using 1 click?

i.e

echo "<a href='".$wpdb->query(" UPDATE partners SET active='no' WHERE partner_id='$active_partner->partner_id' ")."'>Disable</a>";

3 个答案:

答案 0 :(得分:2)

您需要使用ajax函数进行响应。

$('#your_button_id').bind('click', function(){
    function_with_ajax();
})

function function_with_ajax(){
    $.ajax({
        here you could call the update.php script and transmit dynamic data
    });
}

答案 1 :(得分:0)

您需要使用ajax函数对点击做出反应。

$('#your_button_id').bind('click', function(){
    function_with_ajax();
})

function function_with_ajax(){
    $.ajax({
        here you could call the update.php script and transmit dynamic data
    });
}

答案 2 :(得分:0)

<button id="btn-save" type="button">
    save
</button>
<script type="text/javascript">
    jQuery(document.ready(function ($) {

        $("#btn-save").click(
            function () {
                $.ajax({
                    type:"POST",
                    url:"/wp-admin/wp-ajax.php",
                    data:{
                        action:"save_data",
                        data:"data-update",
                        condition:"data-condition"
                    },
                    success:function (response) {
                        console.log(response);

                    },
                    error:function (error) {
                        console.log(error);

                    }
                })
            }
        );

    }))

</script>

并添加到文件功能:

add_action("wp_ajax_save_data",function ()
{
    global  $wpdb;
    $wpdb->update("your-table",
        ["your_field" => $_POST['data']]
        ,["condition-filed"=>$_POST['condition']]);
});