我运行了以下代码,结果发现SESSION变量角色在每次传递时都被数据库输出覆盖。但是,由于SESSION变量甚至没有被调用,这是怎么回事!
<?php
try {
$sth = $dbh->query("SELECT * FROM roles");
while($role = $sth->fetch(PDO::FETCH_OBJ)){
print_r($_SESSION);
if($row->role == $role->id){$selected ='selected="selected"';}
else{$selected ='';}
echo "<option value='$role->id' $selected>$role->role</option>";
}
} catch(PDOException $e) {
echo $e->getMessage();
}
?>
会话变量在
前几页通过此行定义 $_SESSION['role'] = $row->role;