我有两个下拉框,我希望用户从两者中选择值。下拉框填充了页面加载时的查询结果。我希望将这些值存储为会话变量,以便在后续查询中使用。
第一个文件 = choose.php
<html>
<form action="choose2.php" method="post">
<?//db connection stuff taken out from here
}
// fill classes
$result = mysqli_query($con,"SELECT * FROM classes");
echo "<select id='classlist'>";
while($row = mysqli_fetch_array($result))
{
echo " <option value=" . $row['id'] . ">" . $row['classname'] . "</option>";
}
echo "</select>";
//fill schemes of work
$result = mysqli_query($con,"SELECT * FROM schemes_of_work");
echo "<select id='sowlist'>";
while($row = mysqli_fetch_array($result))
{
echo " <option value=" . $row['id'] . ">" . $row['name'] . "</option>";
}
echo "</select>";
mysqli_close($con);
?>
<input type="submit">
</form>
</html>
第二个文件 = choose2.php
<?php session_start();
$_SESSION['classname'] = $_POST["classlist"];
$_SESSION['sowname'] = $_POST["sowlist"];
?>
<?php echo $_SESSION['classname'];?>
<?php echo $_SESSION['sowname'];?>
我无法让它工作 - 我在choose2上得到一个空页面,并且在apache日志中出现以下错误:“未定义的索引:第3行/var/www/assessment/choose2.php中的sowlist,