【问题标题】:how i can send the selected option from the database to the server in php我如何将选定的选项从数据库发送到 php 中的服务器
【发布时间】:2018-07-13 08:02:19
【问题描述】:

我有这个从用户和数据库中获取值的表单(选择标签)

<form class="form-signin" method="POST" action="ajoutement2.php">
        <label class="sr-only" for="Nom_de_la_Categorie2">Nom de la Catégorie</label>
        <input class="form-control" type="text" name="Nom_de_la_Categorie2" placeholder="Nom de la Catégorie" required autofocus><br>
        <select class="custom-select">
            <option disabled selected>sélectionnez la catégorie supérieure</option>
            <?php while($row1 = mysqli_fetch_array($reponse1)):;?>
            <option><?php echo $row1[1];?></option>
            <?php endwhile;?>
        </select><br><br>
        <input class="btn btn-lg btn-primary btn-block" type="submit" value="Ajouter"></form?

我想获取所选选项的值(在选择标签中)以供以后使用

【问题讨论】:

  • 非常粗略的答案,但是给你的
  • 谢谢你,这是我第一次在选择标签中使用数据库,我曾经将值属性放在选项标签中

标签: php html


【解决方案1】:

HTML:

<form class="form-signin" method="POST" action="ajoutement2.php">
  <label class="sr-only" for="Nom_de_la_Categorie2">Nom de la Catégorie</label>
  <input class="form-control" type="text" name="Nom_de_la_Categorie2" placeholder="Nom de la Catégorie" required autofocus><br>
  <select class="custom-select" name="foo">
    <option disabled selected>sélectionnez la catégorie supérieure</option>
    <?php while($row1 = mysqli_fetch_array($reponse1)):;?>
    <option>
      <?php echo $row1[1];?>
    </option>
    <?php endwhile;?>
  </select><br><br>
  <input class="btn btn-lg btn-primary btn-block" type="submit" value="Ajouter">
</form>

PHP:

在您的 PHP 文件 ajoutement2.php 中,您可以使用 $_POST['foo'] 获取选择值,例如:

$parentCategory = $_POST['foo'];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-25
    • 2011-04-03
    • 1970-01-01
    • 2013-12-13
    • 2016-01-12
    • 1970-01-01
    • 2012-07-19
    • 2011-07-28
    相关资源
    最近更新 更多