I have a simple form to update a row in my database and also have a language link/button. SUBMIT button works and writes values to my database. However after I click the link button twice (to go back the same page) I see the old value in the text box. I refresh the page and then I see updated value. It works on Chrome without any problems but somehow Safari caches the database values and doesn't refresh.
Here is my code:
// Get language
if (isset($_GET['language']))
{
$get_lang = $_GET['language'];
if ($get_lang == 'fr') {
$lang_code = 'fr';
}
else if ($get_lang == 'en') {
$lang_code = 'en';
}
else {
$lang_code = 'fr';
}
}
else
{
$php_self = htmlspecialchars($_SERVER["PHP_SELF"]);
header("refresh:0; url=$php_self?language=en");
$lang_code = 'en';
}
include('../inc/config.php');
include('inc/head.php');
global $db;
// Update page
if ( isset($_POST['submit']) )
{
$lang_code = $_GET['language'];
$page_title = $_POST['page_title'];
if ( $lang_code == 'fr' )
{
$updatePage = $db->execute("UPDATE pages SET page_title_fr=? WHERE page_id=1", array($page_title));
}
else if ( $lang_code == 'en' )
{
$updatePage = $db->execute("UPDATE pages SET page_title_en=? WHERE page_id=1", array($page_title);
}
}
// Get page content
$page_content = $db->get_row("SELECT * FROM pages WHERE page_id = 1" );
if ( $lang_code == 'fr' )
{
$page_title = $page_content->page_title_fr;
}
else
{
$page_title = $page_content->page_title_en;
}
and my form :
// Button for changing the language
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?language=<?php if ( $lang_code == 'fr' ) { echo 'en'; } else if ( $lang_code == 'en' ) { echo 'fr'; } ?>"><?php if ( $lang_code == 'en' ) { echo 'FRENCH'; } else { echo 'ENGLISH'; } ?></a>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?language=<?php echo $lang_code; ?>">
<input name="page_title" type="text" value="<?php echo $page_title; ?>">
<button name="submit" type="submit">SAVE</button>
</form>
EDIT : I've tried disabling caching but it didn't help.
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
EDIT 2 : Disabling the cache from Safari's Develop menu fixes the problem