如何从选项值获取 ID

我想知道如何将$row['id']用户选择的内容保存到准备存储到我的数据库的变量中。


我可以解决这样的问题吗?


<form action="shippingmethod.php" method="post" role="form" class="send-it-test">

  <select class="form-control search-slt" name="selezione_sede">

    <?php

      $sql = "SELECT id,city,address FROM sedi ORDER BY city";

      $ris = mysqli_query($db,$sql);

      while($row = mysqli_fetch_array($ris)){

        echo "<option value='" . $row['id']."'>" . $row['city'] ." ,". $row['address']."</option>";

      }

    ?>

  </select>

  <div class="text-center">

    <button type="submit">Send</button>

  </div>

</form>


九州编程
浏览 142回答 1
1回答

猛跑小猪

如果您只想将值保存到数据库中,您可以使用全局变量$_POST作为在同一个 php 文件中。<form action="test.php" method="post" role="form" class="send-it-test">&nbsp; <select class="form-control search-slt" name="selezione_sede">&nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; $sql = "SELECT id,city,address FROM sedi ORDER BY city";&nbsp; &nbsp; &nbsp; $ris = mysqli_query($db,$sql);&nbsp; &nbsp; &nbsp; while($row = mysqli_fetch_array($ris)){&nbsp; &nbsp; &nbsp; &nbsp; echo "<option value='" . $row['id']."'>" . $row['city'] ." ,". $row['address']."</option>";&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; ?>&nbsp; </select>&nbsp; <div class="text-center">&nbsp; &nbsp; <button type="submit" name="submit">Send</button>&nbsp; </div></form><?php&nbsp;if(isset($_POST['submit'])){$value = $_POST['selezione_sede'];}?>
打开App,查看更多内容
随时随地看视频慕课网APP