当用户登录到我的网站时,我创建了一个名为的会话,该会话$_SESSION['session_city_id']
从 MySQL 收集 ID
我想知道是否可以从表单中更改它包含的数据。我创建了如下select_city
所示的表单:
<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>
我的sessions.php
样子是这样的(我刚开始用 PHP 编程,所以不要因为我是一个完整的菜鸟而抨击我!)
<?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
?>