У вас есть пара вещей, которые вы должны исправить, но я думаю, что главная проблема в том, что когда вы перенаправляете, ваше сообщение больше не устанавливается, поэтому вам нужно будет просто опубликовать сообщение прямо на целевой странице:
<form role="form" action="loadpage.php" method="POST" name="theForm" id="theForm">
Затем на этой странице сделайте сеанс. Также я бы сделал функцию для получения вашего запроса, чтобы вы могли выполнить некоторую фильтрацию:
<?php
# You could include this from a separate page, makes your script cleaner
function getRequest($key = false, $type = 'post')
{
switch($type) {
case('get'):
$arr = $_GET;
break;
case('post'):
$arr = $_POST;
break;
default:
$arr = $_REQUEST;
}
if(!empty($key))
return (isset($arr[$key]))? trim($arr[$key]) : null;
return $arr;
}
# Don't put this after any "if" statements, just make it first thing on top of
# every top-level page
session_start();
# Just stop if invalid
if(empty(getRequest('selectedPage')))
die("Invalid request.");
# Assign the session variables
$_SESSION['sayi'] = htmlentities(getRequest('sayi'));
$_SESSION['madde'] = htmlentities(getRequest('madde'));
$_SESSION['tarih'] = htmlentities(getRequest('tarih'));
$_SESSION['selectedPage'] = htmlentities(getRequest('selectedPage'));
# Modify the switch a bit. What you have is not wrong though.
# Make sure to use exit after he redirect so the script doesn't continue to run
switch(getRequest('selectedPage')) {
case "page_0":
# Since everything else redirects, just die here
die("Konu Seçmediniz.");
case "page_1":
$page = "page2_form";
break;
case "page_2":
$page = "page_2";
break;
default:
$page = "page1_form";
break;
}
# Just do one redirect here
header("Location: {$page}.php");
# This may be the end of the script anyway, but best to get in the habit of
# exiting after redirect
exit;
Если вы действительно хотите сначала опубликовать на той же странице, а затем перенаправить, на вашем loadpage.php
вам нужно перенаправить с помощью значение сеанса вместо значения $_POST
:
<?php
switch($_SESSION['selectedPage']) {
case "page_0":
# Since everything else redirects, just die here
die("Konu Seçmediniz.");
case "page_1":
$pg = "page2_form";
break;
case "page_2":
$pg = "page_2";
break;
default:
$pg = "page1_form";
break;
}
# Just do one redirect here
header("Location: {$pg}.php");
exit;
# If this is the end of the script, don't close it with a "?>" it is proper syntax to leave it off
# and then you don't have to worry about any hidden spaces that may mess you
# up down the road.