2017-03-05 20 views
0

ここに私のコードです。私は選択されたオプションの値を取得し、別の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

**あなたは** [SQLインジェクション](http://php.net/manual/en/security.database.sql-injection.php)に大きく開いていると、本当に**準備[使用する必要がありますステートメント](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)**を使用してクエリを連結してください。あなたがユーザーの入力をまったくエスケープしていないからです! –

+2

あなたの実際の質問は何ですか?あなたは私たちに例の質問を示しました。あなたはそれをやろうとしましたか?あなたはどこにいるのですか? –

+0

エラーとは何ですか? – user3526204

答えて

0

この は$ GradeSection = $ _POST [ 'GradeSection']の上にそれを入れてみてください。

if ($GradeSection != "" || $GradeSection != NULL) 
{ 
$sql += "AND SectionName = '$GradeSection'"; 
} 
関連する問題