When a user logs in to my website, i create a session called $_SESSION['session_city_id'] which collects an ID from MySQL
I wonder if it’s possible to change the data it contains from a form. I have created the form select_city which looks like this:
<form name='select_city' action='sessions.php' method='post' style='display:inline;'>
<select onchange='this.form.submit()'>
<option value='1'>The first value</option>
<option value='2'>The second value</option>
<option value='3'>The third value</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>
My sessions.php looks like this (I just started programming in PHP so don’t bash me for being a complete noob!)
<?php
session_start();
$url = htmlspecialchars($_SERVER['HTTP_REFERER']); //Find out where the user came from
if (isset($_POST['select_city'])){
$_POST['select_city'] = $city_id;
if (isset($_SESSION['session_city_id'])){
unset($_SESSION['session_city_id']);
}
$_SESSION['session_city_id'] = $city_id;
}
header ("Location: $url"); //Redirect back to the page the user came from
?>
You can just override you session variable with the new value (no need to unset)
and don’t forget the name in your field