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条)

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏