dongli4711 2017-03-21 04:45
浏览 33
已采纳

当删除按钮已经执行了sql时,我如何刷新此页面(称为add_user.php)

I wanna make delete with confirmation modal, the code below (js) for calling the div where delete modal contains Delete button (class is btn-ok).

HTML :

<a href="" data-href="add_user.php?iduser=<?php echo $iduser; ?>" class="btn btn-xs btn-danger btn-rounded" data-toggle="modal" data-target="#delete">
<i class="fa fa-trash"></i></a>

<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <center>
                <div class="modal-header">
                    <h2><i class="fa fa-trash-o"></i> Konfirmasi Hapus Data</h2>
                </div>
                <div class="modal-body">Anda yakin menghapus data ini?</div>
            </center>
            <div class="modal-footer">
                <center>
                    <button type="button" class="btn btn-default" data-dismiss="modal">Batalkan</button>
                    <a class="btn btn-danger btn-ok">HAPUS SEKARANG</a>
                </center>
            </div>
        </div>
    </div>
</div>

Javascript :

<script>
    $('#delete').on('show.bs.modal', function(e) {
    $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
    });
</script>

PHP :

<?php
require('koneksi.php');
$iduser = $_GET['iduser'];
$sqldel = "UPDATE bf_user_santara SET deleted='1' WHERE iduser='$iduser'";
if (mysqli_query($con, $sqldel)) {
    echo "Record deleted successfully";
    //$_SESSION['sukseshapus'] = 1;
} else {
    echo "Error deleting record: " . mysqli_error($con);
}
?>

But i dont know why, when the mysqli_query($con, $sqldel)) was executed, the page didnt show the message "Record deleted successfully", and i wanna the page reload to add_user.php, how to do that? I've already tried but didnt work for me. Thank you

Sorry for my bad english :)

P.s here i doing soft delete, so data on the database just changed deleted_id, and my query worked, just not working on that message & page reloading

  • 写回答

1条回答 默认 最新

  • dongyu2764 2017-03-21 05:14
    关注

    For reaload the page you can do like this in php.

    header("Location: http://www.yourwebsite.com/add_user.php");
    die();
    

    And for display delete message you should store that message in session. Or you can do it using javascript but for that you need to do this with ajax and in success function you can display the message. So once confirmation model open, on click of OK button, you should redirect to add_user.php either using php or javascript like this:

    window.location = "http://www.yoururl.com";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料