php
  • json
  • forms
  • post
  • 2016-09-07 106 views 1 likes 
    1
      <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> 
    

    嘿家伙。以上是我正在使用的代码。PHP无法从下拉菜单中选择值

    我想要实现的是POST所选值的停止ID并停止NAME(从下拉菜单)到另一个文件,然后将数据添加到mySQL中。

    我现在的问题是,我现在的代码实际上只是发布$ stopid和$ stopname的最后一个设置值,这不是我所需要的。

    我一直坚持这一段时间,我会喜欢它有人在这里可以指向我在正确的方向!

    谢谢

    回答

    3

    移动<select>元素之外的<input>元素。 您只能在您的<select>元素内放置<option>元素。

    我改进了一下你的版本。

    <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> 
    
    相关问题