简体   繁体   English

获取选择表格的价值

[英]Get value of select form

I'm trying to access the value of a select value with php. 我正在尝试使用php访问选择值的值。 The select gets it's options from a database. 该选择从数据库中获取它的选项。

<form action="#" method="post">
        Product:<br>
        <input type="text" name="product"><br>
        Category:<br>
        <select name="category">
            <?php
                $sql = mysqli_query($link, "SELECT name FROM inventory_category");
                while ($row = $sql->fetch_assoc()){
                    echo "<option value=\"Category\">" . $row['name'] . "</option>";
                }
            ?>
        </select><input type="submit" name="submit"></form>

<?php
            if(isset($_POST['submit'])){
                $name = $_POST['product'];
                $category = $_POST['category'];
                echo $name;
                echo '<br>';
                echo $category;?>

I get the expected result for product but not for category which displays as Category instead of the option selected. 我得到了product的预期结果,但没有得到显示为Category而不是所选选项的category的预期结果。

I'm using this as a debug but ultimately I will be storing these chosen values to the database. 我将其用作调试,但最终我会将这些选择的值存储到数据库中。 Is there any difference to how to handle both situations? 处理这两种情况有什么区别?

Thanks in advance. 提前致谢。

value替换为所需的数据:

echo "<option value=\"".$row['name']."\">" . $row['name'] . "</option>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM