My Code looks like this.
fileA.php:
Item stored in DB: <?php echo $stored_item; ?> //displays the last selected item
<form action="fileB.php" method="post" type="submit">
<input type="hidden" name="item" value="itemA">
<button>Save</button></li>
</form>
<form action="fileB.php" method="post" type="submit">
<input type="hidden" name="item" value="itemB">
<button>Save</button></li>
</form>
fileB.php:
changeItem(); ... //Changes the entries in the database, works correctly
header('Location: fileA.php');
Now the entries have been changed in the database, but $stored_item shows the old entry, until i reload the page.
Now I would like to know, how I can refresh the fileA.php automatically after the header('Location: fileA.php');
from fileB.php
I already tried things like:
echo '<script>window.location.reload();</script>';
header("Refresh:0");
But with them the website gets into a infinity-refreshing-loop, also if i use an if-Statement before:
if(isset($_POST)){
echo '<script>window.location.reload();</script>';
unset($_POST);}
You can do it with PHP:
header("Refresh:0");
It refreshes your current page, and if you need to redirect it to another page, use following:
header("Refresh:0; url=page2.php");
you may use header("Refresh:0")
if you need to refresh current page only. If you want to refresh specific page you need to use header("Refresh:0,url:$targeturl")
if you want to redirect on some other page ($targeturl). you may also use header("Refresh:n");
for refreshing page after nth second