我如何从下拉列表中获取city_id的选定值并存储在会话中?
`
<form action="dynamic.php" method="post">
<select name="city" >
<option value="">Select City</option>
<?php
$sql="select * from city ORDER BY city_name";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result)){
?>
<option value="<?php echo $row["city_id"];?>"><?php echo $row["city_name"];?></option>
<?php
}
?>
</select>
</form>
<?php
session_start();
if(!empty($_POST['city'])){
$_SESSION['city'] = $_POST['city'];
}
?>
答案 0 :(得分:0)
您需要session_start();
然后
$ _ SESSION ['city'] ='somecity';
答案 1 :(得分:0)
您需要在使用var:
的每个页面中使用它session_start();
然后你可以添加这个
$_SESSION["myvar"] = "something"