我有三个选项,你可以看到。我只需要课程选项和年份选项。现在我想获取它们的值,以便我可以将它们传递给我的查询。这里的问题是,它们是基于不同的表进行查询的,当我尝试将Section的$ _POST传递给变量并查询它时,错误表明未定义的索引。我该怎么办?感谢
这是两个选项的代码:
<div class="col-md-3 pull right">
<label>Course</label>
<select class="form-control" name="course" id="courseselect">
<?php
$query= mysqli_query($con,"SELECT * FROM course");
$numrows=mysqli_num_rows($query);
if($numrows !=0 ){
while($row=mysqli_fetch_assoc($query)) {?>
<option value="<?php echo $row['courseid'];?>"><?php echo $row['coursedesc'];?></option>
<?php }
}
?>
</select>
</div>
<div class="col-md-2 pull right">
<label>Year</label>
<select class="form-control" name="year">
<?php
$query= mysqli_query($con,"SELECT * FROM year");
$numrows=mysqli_num_rows($query);
if($numrows !=0 ){
while($row=mysqli_fetch_assoc($query)) {?>
<option ><?= $row['yearnum'];?></option>
<?php }
}
?>
</select>
</div>
这是我的查询
$cid=$_POST['courseid'] //the value from the Course option
SELECT t1.studentno, t1.firstname, t1.lastname, t1.yearid, t2.coursedesc
FROM
students as t1
INNER JOIN course as t2
ON $cid=t2.courseid
LEFT JOIN paidstudents as t3
ON t1.studentno = t3.studentno
WHERE
t1.studentno IS NOT NULL
AND t3.studentno IS NULL
$ cid表示未定义的索引
我想将courseid和yearid替换为上面的post值。谢谢
答案 0 :(得分:0)
您的表单选择是:
<select class="form-control" name="course" id="courseselect">
所以发布的字段为course
,但在您的代码中执行:
$cid=$_POST['courseid']
所以要么
$cid = $_POST['course'];
或
<select class="form-control" name="courseid" id="courseselect">
使表单字段名称与您尝试访问的POST变量匹配。