简体   繁体   English

PHP无法从下拉列表中POST所选值

[英]PHP can't POST the selected value from a dropdown

          <form action="addbusstop.php" method="POST" id="produceJSON" enctype="multipart/form-data">
        <?php
        echo "<div class = 'dropdown_container'><select class = 'dropdown select xs-mt1' name = 'line' id = 'line'>";
        foreach($ptv_json_bus as $item)
        {
          $stopid = $item['stop_id'];
          $stopname = $item['location_name'];

          ?>

          <option value = "<?php echo $stopid;?>"> <?php echo $stopname;?></option>

          <?php
        }//end foreach
        ?>
        <input type = "hidden" value ="<?php echo $stopid; ?>" name="stop_id" id="stop_id">
        <input type = "hidden" value ="<?php echo $stopname; ?>" name="stop_name" id="stop_name">
      </select>

      <button type="submit" class="button button-latrobe-orange xs-ml2" onclick="changeState3()" id="submitstop2" name="submitstop2">OK</button>
    </div>


  </form>

Hey guys. 大家好。 Above is the code I'm working with. 以上是我正在使用的代码。

What I am trying to achieve is to POST the selected value's stop ID and stop NAME (from a dropdown) to another file which then adds the data into mySQL. 我想要实现的是POST所选值的停止ID并停止NAME(从下拉列表)到另一个文件,然后将数据添加到mySQL中。

What my problem is right now is that the current code I have is actually only POSTing the last set value of $stopid and $stopname which is not what I need. 我现在的问题是,我当前的代码实际上只是POST了$ stopid和$ stopname的最后一个设置值,这不是我需要的。

I've been stuck on this for quite a while and I would love it it somebody here could point me in the right direction!! 我已经被困在这一段时间了很长一段时间我会喜欢它,这里有人可以指出我正确的方向!

Thank you 谢谢

Move your <input> elements outside of the <select> element. <input>元素移动到<select>元素之外。 You can only put <option> elements inside of your <select> element. 您只能将<option>元素放在<select>元素中。

I've improved your version a bit. 我已经改进了你的版本了。

<form action="addbusstop.php" method="POST" id="produceJSON" enctype="multipart/form-data">
    <div class = 'dropdown_container'>
        <select class="dropdown select xs-mt1" name="line" id="line">
            <?php
            foreach ($ptv_json_bus as $item) {
                $stopid = $item['stop_id'];
                $stopname = $item['location_name'];
                echo "<option value='$stopid'>$stopname</option>";
            }
            ?>
        </select>
        <input type="hidden" value="<?php echo $stopid; ?>" name="stop_id" id="stop_id">
        <input type="hidden" value="<?php echo $stopname; ?>" name="stop_name" id="stop_name">

        <button type="submit" class="button button-latrobe-orange xs-ml2" onclick="changeState3()" id="submitstop2" name="submitstop2">OK</button>
    </div>
</form>

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

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