ok so i have only just stared using pdo but am slowlys getting the hang of it and i am wanting to know how to make a drop down menu or list pox populate the data into the fields on the page i have started the code by looking up pdo guides etc but im having trouble finiding a solution for this. also sorry for the untidy code but again i am new to the whole programming scene
thanks in advice here is my code for it 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');
?>
that also includes my session cookie but that works great and 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 poulate are txt_exam_id, txt_location, txt_date_taken, txt_exam_taken, txt_grade_recieved
The answer is simple: do not populate dropdown menus through pdo code
That's totally different matters which should never be intrmixed in the code.
Separate your code into 2 parts:
write and debug these parts separately.
now you have your exams stored in $data array.