dongqiao2077 2015-06-23 16:59
浏览 116
已采纳

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.

  1. <?php
  2. mysql_connect("localhost", "root","") or die(mysql_error());
  3. mysql_select_db("efszf_a") or die(mysql_error());
  4. $query = "SELECT nev FROM tanulok";
  5. $result = mysql_query($query) or die(mysql_error()."[".$query."]");
  6. ?>
  7. <select name="tanulok">
  8. <?php
  9. while ($row = mysql_fetch_array($result))
  10. {
  11. echo "<option value=".$row['nev'].">".$row['nev']."</option>";
  12. }
  13. ?>
  14. </select>

Please help me. Regards

  • 写回答

2条回答 默认 最新

  • dongpu9852 2015-06-23 17: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部