显示其他会话时未显示会话消息

时间:2019-02-22 10:30:21

标签: php session mysqli

我具有保存和删除按钮的功能,当我按下“保存”按钮时,会显示会话消息,但是当我按下“删除”按钮时,会话消息不会出现

此处admin_tools.php:

<?php require_once 'admin_process.php'; ?>
<?php 
if (isset($_SESSION['msg'])) :?>
    <div class="text-center alert alert-<?=$_SESSION['msg_type']?>">
        <a href="#" class="close" data-dismiss="alert">&times;</a>
    <?php 
        echo $_SESSION['msg'];
        unset($_SESSION['msg']) ;
     ?>
    </div>
 <?php endif ?>

admin_process.php:

include "config.php"; 

session_start();

if (isset($_POST['save'])) {
    $nama_staff = $_POST['nama_staff'];
    $user_staff = $_POST['user_staff'];
    $pw_staff = md5($_POST['pw_staff']);
    $cabang = $_POST['cabang']; 

    $tambah = mysqli_query($conn,"INSERT INTO staff(nama_staff,user_staff,pw_staff,cabang) VALUES('$nama_staff','$user_staff','$pw_staff','$cabang')");
    if ($tambah) {
        mysqli_query($conn,$tambah);
        $_SESSION['msg'] = "Staff berhasil ditambahkan";
        $_SESSION['msg_type'] = "success";
        header('location:admin_tools.php');
    }
}

if (isset($_GET['delete'])) {
    $id_staff = $_GET['delete'];
    $hapus = mysqli_query($conn,"DELETE FROM staff WHERE id_staff=$id_staff");
    if ($hapus) {
        mysqli_query($conn,$hapus);
        $_SESSION['msg'] = "Staff berhasil dihapus";
        $_SESSION['msg_type'] = "danger";
        header('location:admin_tools.php');
    }
}

0 个答案:

没有答案
相关问题