dpy83214 2018-04-03 14:45
浏览 102
已采纳

如何从选择表单输入中显示的值发布不同的值

On my webpage i have the below form. I am using some PHP to display the name of users in the select input. My question is this... how do I save down the id column (that I am selecting in the SQL) to the database instead of the name columns that I am displaying? All help greatly appreciated.

<form action='insertmodule.php' method='POST'>
                <span class="form-group">
                    <input type="text" placeholder="Name" class="form-control" name="name" required/>
                </span>
                <br>
                <div class="form-group">
                   <label for="exampleSelect1">Select the tutor for the module</label>
                    <select class="form-control" name="tutor">
                      <?php
                        include('../connections/conn.php');
                        $sql = mysqli_query($conn, "SELECT id, first_name, last_name FROM cater_users WHERE role = 2");
                        while ($row = $sql->fetch_assoc()){
                        echo "<option>" . $row['first_name'] . " ". $row['last_name'] . "</option>";
                        }
                      ?>
                    </select>
                 </div>


                <button type="submit" class="btn btn-primary" name='sign'>Create</button>
            </form>
  • 写回答

1条回答 默认 最新

  • douke3007 2018-04-03 15:16
    关注

    try this

    echo sprintf('<option value="%s">%s %s</option>', $row['id'], $row['first_name'], $row['last_name']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料