我想在一页上显示许多会话消息。 第一页是 file_upload.php
// Success!
echo "File was uploaded without errors.<br />" . $_SESSION['message'];
echo "File name is '{$file_name}'.<br />" . $_SESSION['message'];
echo "File references an uploaded file. <br />" . $_SESSION['message'];
echo "File was uploaded without errors" . $_SESSION['message'];
第二个文件是 new.php ,这里是$sql = "INSERT INTO products ";
(cat_id,产品名称,文件名,类型,大小,文件名2,类型2,大小2,位置,可见性,内容)
$result = insert_products($products);
if($result === true) {
$new_id = mysqli_insert_id($db);
$_SESSION['message'] = 'The product has been created.';
redirect_to(url_for('/staff/pages/show.php?id=' . $new_id));
第三个是 show.php ,这是函数。
<?php echo display_session_message(); ?>
function get_and_clear_session_message() {
if(isset($_SESSION['message']) && $_SESSION['message'] != '') {
$msg = $_SESSION['message'];
unset($_SESSION['message']);
return $msg;
}
}
function display_session_message() {
$msg = get_and_clear_session_message();
if(!is_blank($msg)) {
return '<div id="message">' . h($msg) . '</div>';
}
}
目前,仅在show.php中显示“产品已创建”消息。 可以在一页上显示许多会话消息吗?我想添加所有错误消息表单功能 file_upload.php 。