PDO を使い始めたばかりですが、徐々にコツを掴んでいます。ドロップダウン メニューまたはリスト ボックスでページのフィールドにデータを入力する方法を知りたいです。PDO ガイドなどを調べてコードを開始しましたが、これに対する解決策を見つけるのに苦労しています。また、乱雑なコードで申し訳ありませんが、プログラミングシーン全体に不慣れです。
前もって感謝します。これまでのコードは次のとおりです。接続文字列は次のとおりです。
<?php
session_start();
if(!isset($_SESSION["user_id"])){
header("location:../Pages/login.html");
}
//databse connection Sting
$connection = new PDO("sqlsrv:server=servername;Database=databasename", "username", "password");
//insertion function
$smt = $connection->prepare('select exam_id From exam');
?>
これには私のセッション Cookie も含まれていましたが、うまく機能します。これが私がこれまでに持っているドロップダウンボックスの人口です。
<select name="lst_exam" id="lst_exam">
<?php
$smt->execute();
while ($row = $smt->fetch()){
echo "<option>" . $row["exam_id"] . "</option>";
}
$connection = null;
if(isset($_POST["lst_exam"]));
?>
</select>
入力しようとしているテキスト ボックスは、txt_exam_id、txt_location、txt_date_taken、txt_exam_taken、txt_grade_recieved です。