Hello,
I have created many functions and I am trying to show messages ie when user successfully registered invalid username password invalid this and that I tried to do so using the session_start concept please let me know if this is a good approach or should i do another way if possible as this is not working.
Here is how I created.
my structure path is :
mainfolder>includes>functions.php (Where all of my fucntions are currently stored in)
mainfolder>index.php where I want to display the message
My code functions.php
session_start();
function message() {
if(isset($_SESSION['message'])) {
$output = "<div class='msg'>";
$output .= $_SESSION['message'];
$output .= "</div>";
unset($_SESSION['message']);
return $output;
}
}
function adduser($connect) {
(all my other code)
if($insert) {
$_SESSION["msg"] = "You have successfully registered";
header("Location: login.php");
} else {
$_SESSION["msg"] = "There were some errors";
header("Location: signup.php");
}
}
function update_user($connect, $id) {
(All my other code)
if($insert) {
$_SESSION["msg"] = "You information have been successfully updated";
header("Location: user.php?uid=".$_SESSION["uid"]);
} else {
$_SESSION["msg"] = "There were some errors";
header("Location: user.php?uid=".$_SESSION["uid"]);
}
}
and on index.php I simply do this <?php echo message(); ?> But the message is not showing up though. Now I have noticed one thing when I remove unset($_SESSION['message']); from my message function then message will be shown up but never ever removes as it's stored in session and will be remoevd once session is destroyed so what should I do now?
Thank You