获取select的值

时间:2017-03-05 12:35:07

标签: javascript php html mysql

这是我的代码。我想获取所选选项的值并在另一个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'];
?>

1 个答案:

答案 0 :(得分:0)

试试这个 把它放在$ GradeSection = $ _POST ['GradeSection'];

之上
if ($GradeSection != "" || $GradeSection != NULL)
{
$sql += "AND SectionName = '$GradeSection'";
}