从填充的下拉列表中获取价值 [英] Getting value from populated drop down list

查看:49
本文介绍了从填充的下拉列表中获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从数据库中填充了一个下拉列表,但我不认为该值被设置为用户从下拉列表中选择的名称,因为在选择表单时,没有向数据库添加任何值.

I have populated a drop down list from the database but i dont think the value is being set to the name the user chooses from the drop down as when the form is selected, no value is added to the database.

目前,它显示了该表中的所有名称.正如我所说,我希望该值是用户选择的名称,以便在提交表单时将其添加到数据库中并可以在另一个页面上获取.

At the moment, it shows all the names from that table. As i said, i want the value to be the name the user chooses so that when the form is submitted it is added to the database and can be fetched on another page.

<select name="category">
<?php 
    $sql = mysql_query("SELECT category_Name FROM category");
    while ($row = mysql_fetch_array($sql)){
        echo '<option value="'.$category_Name.'">' . $row['category_Name'] . "</option>";
    }
?>

推荐答案

echo '<option value="'.$category_Name.'">' . $row['category_Name'] . "</option>";
                    // ^ this var is never set

应该

echo '<option value="'.$row['category_Name'].'">' . $row['category_Name'] . "</option>";
//                       ^ change this

或者你可以这样拥有

echo '<option>' . $row['category_Name'] . "</option>";

如果未设置值,则只取显示名称的值.

If value is not set, it just takes the value of the display name.

这篇关于从填充的下拉列表中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆