I have just started using PDO but I am slowly getting the hang of it. I want to know how to make a drop down menu or list box populate the data into fields on a page. I have started the code by looking up PDO guides etc, but I am having trouble finding a solution for this. I am also sorry for the untidy code but again I am new to the whole programming scene.
Thanks in advance. Here is my code so far: Here is the connection string:
<?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');
?>
This also included my session cookie, but that works great. Here is the population of the drop down box I have so far.
<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>
The text boxes I am trying to populate are txt_exam_id, txt_location, txt_date_taken, txt_exam_taken, txt_grade_recieved