dst2007 2017-06-15 12:48
浏览 96
已采纳

如何修改下拉菜单中选择的行的SQL数据?

I'm beginning in PHP and I've been tasked to create a form with which the user can select a category (a row from a table in the MySQL Database) and update the content of a specific column in that row.

Here is what it looks like. Here is what the table in MySQL looks like (tva is the column in which I want to update the content)

Here is what the code looks like :

<tr>
  <td>Modify the TVA of :  </td>
  <td>
    <select name="tva_modif">
    <?
    $sql_tva_modif = "SELECT id_type, nom_fr,tva
                      FROM type
                      ORDER BY nom_fr
                     ;";
    $sql_tva_modif_result = mysql_query($sql_tva_modif);
    while($val_tva_modif = mysql_fetch_array($sql_tva_modif_result))
    {
        echo "<option value='" . $val_tva_modif["id_type"] . "'>" . $val_tva_modif["nom_fr"] . "</option>";
    }
    ?>
  </select>
  <input name="tva_val" id="tva_val" type="text" value=""></div>
  </td>
</tr>

If possible, can someone explain me how to make sure that the input type text field display the TVA value of the selected option and how to make that field update the content of that column in my database ?

</div>
  • 写回答

4条回答 默认 最新

  • doubu5035 2017-06-15 13:01
    关注

    You are using id_categorie field which is not mention in select query

    <?php
        $sql_tva_modif = "SELECT id_type, nom_fr,tva
                  FROM type
                  ORDER BY nom_fr
                   ;";
        $sql_tva_modif_result = mysql_query($sql_tva_modif);
    ?>
    
    <tr>
      <td>Modify the TVA of :  </td>
      <td>
        <select name="tva_modif" id="tva_modif">
        <?php
          while($val_tva_modif = mysql_fetch_array($sql_tva_modif_result))
          {
            echo "<option value='" . $val_tva_modif["id_type"] . "' id='" . $val_tva_modif["tva"] . "' >" . $val_tva_modif["nom_fr"] . "</option>";
          }
        ?>
      </select>
      <input name="tva_val" id="tva_val" type="text" value=""></div>
      </td>
    </tr>
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>
    
        <script type="text/javascript">
        $('#tva_modif').change(function()
        {
            var id = $(this).children(":selected").attr("id");
            if(id != ""){
                $('#tva_val').val(id);
            }
            else
            {
              $('#tva_val').val('');
            }
        });
    
        </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'
  • ¥15 r语言神经网络自变量重要性分析