这是我的代码。我想获取所选选项的值,并在另一个SQL查询中使用该值。
例如:SELECT * FROM section WHERE GradeLevel = '$GradeLevel' AND SectionName = '$GradeSection
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "sample";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$GradeLevel = $_GET['glevel'];
$StudentID = $_GET['studentID'];
$BirthCertificate = $_POST['BirthCertificate'];
$GoodMoral = $_POST['GoodMoral'];
$ReportCard = $_POST['ReportCard'];
echo 'Grade Level : '.$GradeLevel.' <br/>';
//Section
$sql = "SELECT * FROM section WHERE GradeLevel='$GradeLevel'";
$result = $conn->query($sql);
if ($result->num_rows > 0) { ?>
Section Name:
<select name="GradeSection" id="GradeSection" style="width:30%;">
<?php
while($row = $result->fetch_assoc()) {
$Section = $row["SectionName"];
echo '
<option value="'.$Section.'"> '.$Section.' </option> ';
}
echo "</select>";
}
$GradeSection = $_POST['GradeSection'];
?>
最佳答案
尝试这个
将其放在$ GradeSection = $ _POST ['GradeSection'];之上;
if ($GradeSection != "" || $GradeSection != NULL)
{
$sql += "AND SectionName = '$GradeSection'";
}