My code when F5 re-executes a query:
if (isset($_POST['addnewproject']) )
{
include("query/pm_addnewproject.php");
echo $emailnotificationmessage;
}
To prevent query re-execution after pressing F5 or page reload I have to modify a header and place it in the first rules (before any output) of the .php page. So:
if (isset($_POST['addnewproject']) )
{
include("query/pm_addnewproject.php");
header("Location:pm_configureaccounting.php?edit=$_SESSION[accidsession]");
echo $emailnotificationmessage; exit();
}
Because of the header, I now lose the $emailnotificationmessage I wanted to echo out somewhere middle of the page.
What's the best thing to do now when I want to still echo this out?
Now I changed the $emailnotificationmessages to $_SESSION['emailnotificationmessage'] and echo it out where I want it.
But I need to unset this session too, else it keeps showing the user.
So when I place echo $_SESSION['bla']
somewhere middle of the page, it has a value there. It works. But I need to clear it after so when the user visits again, it wont show any message unless project is added again. So I place $_SESSION['bla'] = "";
at the end of the page, and still, this SESSION gets the value ""
?! How is this possible?
Alright. Why dont you write the code in the below way:
<?php
if (isset($_POST['addnewproject']) )
{
include("query/pm_addnewproject.php");
$_SESSION['emailMsg'] = $emailnotificationmessage;
header("Location:pm_configureaccounting.php?edit=$_SESSION[accidsession]");
exit();
}else{
echo $_SESSION['emailMsg'];
}
?>