dongqiao2077 2015-06-24 00:59
浏览 114
已采纳

PHP从下拉列表中获取文本或值

I need a help again.

I need to solve the next problem.

I have to fill one dropdown list from database. If the user select one value, and press the submit button, I have to send the user to the next page, and I should show for all details from this selected value.

Like if the selected value is Monitor, on the next page I have to show the price,and product name and etc in one table.

But I can't figure out how can I get the selected value from this dropdown list and what I should do. This is my code, what is generate my dropdown list and working well.

<?php
mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("efszf_a") or die(mysql_error());

$query = "SELECT nev FROM tanulok";
$result = mysql_query($query) or die(mysql_error()."[".$query."]");
?>

<select name="tanulok">
<?php 
while ($row = mysql_fetch_array($result))
{
    echo "<option value=".$row['nev'].">".$row['nev']."</option>";
}
?>        
</select>

Please help me. Regards

  • 写回答

2条回答 默认 最新

  • dongpu9852 2015-06-24 01:09
    关注

    You need to put your select inside of a form, and have the form submission point to your next page. Like:

    <form action='[yourNextPage.php]' method='post'>
        <select name="tanulok">
        <?php 
        while ($row = mysql_fetch_array($result))
        {
            echo "<option value=".$row['nev'].">".$row['nev']."</option>";
        }
        ?>        
        </select>
        <input type='submit' value='Submit'>
    </form>
    

    Then in your next page, you can access the value the user selected through the $_POST array, like:

    $_POST['tanulok']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效