After a form submit, I am redirecting to the mentioned header location using below codes:
PHP Part:
$TestMessage = "This is a sample message. This is not a constant value. Original data will be collecting from DB";
if(mysqli_affected_rows($conn) > 0) {
header('Location:mydaomain/expenses?success=1');
}else{
header('Location:mydomain/expenses?failed=1');
}
HTML Part:
<div class="SubResult" id="SubResult" >
<?php
if ( isset($_GET['success']) && $_GET['success'] == 1 )
{
echo $TestMessage;
echo "<h1 style='color:green;padding:3%;'>Success !!</h1>";
}
if ( isset($_GET['failed']) && $_GET['failed'] == 1 )
{
echo $TestMessage;
echo "<h1 style='color:red;padding:3%;'>SQL Error !!</h1>";
}
?>
</div>
Issue with the above code is,HTML wont display $TestMessage PHP variable content.
Why I am using this header option in PHP:
Earlier, form was getting submitted whenever I refresh the page after an original submit. I found this solution to avoid that issue. When I remove this header part from php file, I am able to echo variable to PHP (But at that I am facing issue with the form submission on page refresh issue)
Is there any way I can echo this variable to HTML ?