doufulian4076
2014-06-04 14:12
浏览 34
已采纳

我有几个下拉列表 - 我想打印出这些下拉列表的选定选项

This is what I got so far, it's just the dropdown list. It's a form for making a reservation for appointment. I want to print out these selected values (= selected options of dropdown) But I have no clue since I'm very new with PHP and HTML. Something with $_POST and $_GET ? Could I have some suggestions of solution? Much gratitude.

<html>
    <head>
        <title>title</title>
    </head>
    <body>

        <select name="Ar" id="Ar">
<option value="1">2014</option>
<option value="2">2015</option>
<option value="3">2016</option>
<option value="4">2017</option>
<option value="5">2018</option>
<option value="6">2019</option>


</select>

        <select name="Manad" id="Manad">
<option value="1">Januari</option>
<option value="2">Februari</option>
<option value="3">Mars</option>
<option value="4">April</option>
<option value="5">Maj</option>
<option value="6">Juni</option>
<option value="7">July</option>
<option value="8">Augusti</option>
<option value="9">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">December</option>

</select>

        <select name="Dag" id="Dag">
<option value="1">Mandag</option>
<option value="2">Tisdag</option>
<option value="3">Onsdag</option>
<option value="4">Torsdag</option>
<option value="5">Fredag</option>

</select>

        <select name="Tid" id="Tid">
<option value="1">07:00</option>
<option value="2">08:00</option>
<option value="3">09:00</option>
<option value="4">10:00</option>
<option value="5">11:00</option>
<option value="6">12:00</option>
<option value="7">13:00</option>
<option value="8">14:00</option>
<option value="9">15:00</option>
<option value="10">16:00</option>
<option value="11">17:00</option>
<option value="12">18:00</option>

</select>
<input type="submit" name="submit" id="submit" value="Boka" />




    </body>
</html>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doqau82086 2014-06-04 14:15
    已采纳

    You're missing the <form> tag. It should be wrapped around all your form-data (select, input) etc. Then you will fetch it using either $_GET or $_POST or even $_REQUIRE

    Example (change site.php to whatever you please):

    <html>
       <head>
          <title>title</title>
       </head>
       <body>
          <form method="post" action="site.php">
             <select name="Ar" id="Ar">
                <option value="1">2014</option>
                <option value="2">2015</option>
                <option value="3">2016</option>
                <option value="4">2017</option>
                <option value="5">2018</option>
                <option value="6">2019</option>
             </select>
             <select name="Manad" id="Manad">
                <option value="1">Januari</option>
                <option value="2">Februari</option>
                <option value="3">Mars</option>
                <option value="4">April</option>
                <option value="5">Maj</option>
                <option value="6">Juni</option>
                <option value="7">July</option>
                <option value="8">Augusti</option>
                <option value="9">September</option>
                <option value="10">Oktober</option>
                <option value="11">November</option>
                <option value="12">December</option>
             </select>
             <select name="Dag" id="Dag">
                <option value="1">Mandag</option>
                <option value="2">Tisdag</option>
                <option value="3">Onsdag</option>
                <option value="4">Torsdag</option>
                <option value="5">Fredag</option>
             </select>
             <select name="Tid" id="Tid">
                <option value="1">07:00</option>
                <option value="2">08:00</option>
                <option value="3">09:00</option>
                <option value="4">10:00</option>
                <option value="5">11:00</option>
                <option value="6">12:00</option>
                <option value="7">13:00</option>
                <option value="8">14:00</option>
                <option value="9">15:00</option>
                <option value="10">16:00</option>
                <option value="11">17:00</option>
                <option value="12">18:00</option>
             </select>
             <input type="submit" name="submit" id="submit" value="Boka" />
          </form>
       </body>
    </html>
    

    PHP example:

    if(isset($_POST['Ar'])) { // Make sure it's sent
        $year = $_POST['Ar'];
        echo "År: " . htmlentities($year); // Output (htmlentities for safety when outputting)
    
        $month = $_POST['Manad'];
        echo "Månad: " . htmlentities($month);
    }
    
    点赞 评论

相关推荐 更多相似问题