現在、mysqli ステートメントを使用して SQL インジェクションを防止しようとしています。ただし、この移行を完了した後、データベースから結果を取得できなくなりました。ユーザーが年間隔、月、場所を絞り込んで経済データを選択できるフォームがあります。現在のコーディングの問題は次のとおりです。
<?php
if (isset($_POST['submitted'])) {
$gYear = $_POST["year"];
$gYear2 = $_POST["year2"];
$gMonth = $_POST["month"];
$gSelect = $_POST["location"];
if ($gYear > $gYear2) {
die('ERROR: Your second year cant be a time period before the first year you selected');
}
else {
$query = $conn->prepare("SELECT $gSelect, Year FROM unemployed WHERE year BETWEEN ? AND ? and month= ?");
$query->bind_param('sss', $gyear, $gYear2, $gMonth);
$query->execute();
$result = = $conn->query($query)
echo"<table>";
echo "<tr><th>Year</th><th>Time</th><th>$gSelect</th></tr>";
while ($row = $result->fetch_object()){
echo "<tr><td>";
echo $row->Year;
echo "</td><td>";
echo $gMonth;
echo "</td><td>";
echo $row->$gSelect;
echo "</td></tr>";
}
echo "</table";
}
} // end of main if statement
?>
インジェクションを防ぐためにクエリを更新する前に機能しました。皆さんが疑問に思っている場合に備えて、現在、これに取り組むためにphp 5.2.14を使用しています。ステートメントがありませんか?私の問題が何であるかを理解するのを手伝ってくれる人はいますか? どんな助けでも大歓迎です。