I have a problem concerning my drop-down list in PHP. I have in fact 2 tables.
The first is the table feedbacks
with several fields (id_feedback, lesson_feedback, description_feedback, fk_candidat)
My second table is candidats
with 3 fields (id_candidat, name_candidat, firstname_candidat)
When I want to add a recordery from my form feedbacks
.
I must to get the fields below lesson_feedback, description_feedback, name_candidat (with a drop-down-list), firstname_candidat (with a drop-down-list)
.
My problem is I don't recover the fk_candidat for the firstname_candidat. I recover the fk_candidat for the name_candidat only. I need of the name and of the firstname.
Here is an idea of the code
if(isset($_POST['lesson_feedback']) AND isset($_POST['description_feedback']) AND isset($_POST['fk_candidat'])){
$lesson_feedback = htmlspecialchars($_POST['lesson_feedback']);
$description_feedback = htmlspecialchars($_POST['description_feedback']);
$fk_candidat = ($_POST['fk_candidat']);
$req_add = $db->prepare("INSERT INTO feedbacks (lesson_feedback,description_feedback, fk_candidat) VALUES (?,?,?)");
$req_add->execute(array($lesson_feedback, $description_feedback, $fk_candidat));
}
$sql = $db->query("SELECT * FROM candidats");
In HTML
<form action="add_feedbacks.php" method="POST">
<table>
<tr><td>Lesson:</td><td><input type="text" name="lesson_feedback'"/></td></tr>
<tr><td>Description:</td><td><input type="text" name="description_feedback'"/ </td></tr>
<tr><td>Name candidat:</td><td><select name="fk_candidat" style="width:148px">
<?php
while($row = $sql->fetch()) {
?>
<option value="<?= $row['id_candidat']; ?>"><?= $row['name_candidat'];?> </option>
<?php
}
?>
</select>
<tr><td>Firstname candidat:</td><td><select name="fk_candidat" style="width:148px">
<?php
while($row = $sql->fetch()) {
?>
<option value="<?= $row['id_candidat']; ?>"<?= $row['firstname_candidat'];?></option>
<?php
}
?>
</select>
<tr><td colspan="2"><input class="button" type="submit" value="Ajouter"/>
</td></tr>
</table>
</form>
I think my problem is here ?
<tr><td>Firstname candidat:</td><td><select name="fk_candidat" style="width:148px">
<?php
while($row = $sql->fetch()) {
?>
<option value="<?= $row['id_candidat']; ?>"<?= $row['firstname_candidat'];?></option>
<?php
}
?>
</select>