提问人:Alex 提问时间:7/16/2021 更新时间:7/16/2021 访问量:260
其他会话工作时不显示会话消息
Session message not displayed while other session are working
问:
我有一个添加更新和删除按钮,添加按钮和更新工作正常,并相应地显示我的会话消息和msg_type,但是当我单击删除按钮时,即使记录被删除,我也不会收到任何会话消息。我所有的添加、更新和删除文件都来自一个名为 authController 的同一个文件,我在文件的开头调用了一个session_start函数。
在我的PHP文件中,我调用该函数来显示会话消息
<?php if (isset($_SESSION['message'])): ?>
<div class="alert alert-<?=$_SESSION['msg_type']?>">
<?php
echo $_SESSION['message'];
unset($_SESSION['message']);
?>
</div>
<?php endif ?>
这是我authController.php中的删除功能;
if(isset($_POST['delete_employee'])) {
$name = $_POST['name'];
$email_address = $_POST['email_address'];
$address = $_POST['address'];
$telephone = $_POST['telephone'];
$role = $_POST['role'];
$competency = $_POST['competency'];
$key = $_POST['keyToDelete'];
//check if records exists to delete or not
$sql= "DELETE FROM employees WHERE id='$key'";
$result= mysqli_query($db, $sql);
if($result) {
//send flash messages
$_SESSION['message'] = "Employee record Deleted !";
$_SESSION['msg_type'] = "danger";
header("Location: Employee.php");
}
}
if(isset($_POST['add_job'])) {
$job_name = $_POST['job_name'];
$department = $_POST['department'];
$competency = $_POST['competency'];
$competent=implode(',',$competency);
$sql = "INSERT INTO job (`job_name`, `department`, `competency`) VALUES ('$job_name', '$department', '$competent')";
$result = mysqli_query($db, $sql);
if($result) {
$_SESSION['message'] = "Job Role succesfully added !";
$_SESSION['msg_type'] = "success";
header("Location: Job.php");
}
}
此外,当我调用另一个页面中的另一个添加函数时,记录已成功添加,但未显示会话消息。有人可以告诉我我在哪里犯了错误,因为我找不到错误,除了未显示的会话消息外,一切似乎都正常工作。
答: 暂无答案
评论
<div>