【发布时间】:2018-11-08 16:18:53
【问题描述】:
我正在尝试创建一个连接的 SQL 查询以填充 HTML 下拉列表,但它似乎无法正常工作,我不知道为什么。我没有收到任何错误消息或任何东西。下拉列表根本没有填充。肯定有信息应该在下拉列表中,这不是下拉列表缺少数据的问题,而是代码的问题。
<select name="term3sport">
<option value=" " selected disabled>Please select a third term sport...</option>
<?php
include_once('connection.php');
try{
$stmt = $conn->prepare(
"SELECT DISTINCT Choices.Choice_ID, Sports.name
From Sports
INNER JOIN Choices ON Choices.Sport_ID = Sports.Sport_ID
INNER JOIN Year ON Year.Year_ID = Choices.Year_ID
Where Code Like CONCAT('%', :year, '%')
AND Current='Y' AND (Sex=':sex' OR Sex='B') AND Term_ID='3' AND Year_ID=".$row['Year_ID']." ");
$stmt->bindParam(':year', $_SESSION['year']);
$stmt->bindParam(':sex', $_SESSION['sex']);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
echo("<option value='".$row['Choice_ID']."'>".$row['Name']."</option>");
}
}
catch(PDOException $e)
{
echo "error".$e->getMessage();
}
$conn=null;
?>
<input type="submit" value="Submit Choices">
</select>
【问题讨论】:
-
您的代码应该正在检查错误。