如何将下拉列表的选定值存储为mysql中的id

时间:2016-02-24 07:42:55

标签: php html mysql insert dropdown

我从构建器表中获取数据,并在下拉列表中显示它是代码。

<select style="width:154px;">
      <?php 

        include('connection.php');
        $show_builder = "SELECT * FROM builders";
        $result_builder = mysqli_query($conn,$show_builder);
        while($data_builder = mysqli_fetch_array($result_builder)){

            echo"<option>".$data_builder['builder_name']."</option>";
        }
        ?>

我想选择一个值,并将其作为id存储在用户表格中,作为表格中的builder_id

2 个答案:

答案 0 :(得分:0)

简而言之,您必须拥有name的{​​{1}} attr,并将select添加为builder_id代码的value attr:

option

答案 1 :(得分:0)

<?php 
    include('connection.php');
    $show_builder = "SELECT * FROM builders";
    $result_builder = mysqli_query($conn,$show_builder);
    echo '<select name="builder">';
    while($data_builder = mysqli_fetch_array($result_builder)){

        echo'<option value="'.$data_builder['id'].'" >'.$data_builder['builder_name'].'</option>';
    }
    echo "</select>";
?>