dounieqi6959 2019-01-14 23:47
浏览 11

带有2个下拉列表的外键

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.

enter image description here

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?