How do i store select value into a php variable

前端 未结 4 1405
日久生厌
日久生厌 2021-01-21 05:06

i have a simple drop down select menu.

提交评论

  • 2021-01-21 05:22
    <form action="" method="post">
    <div id="select">
    <select class="select" name="selectoptionname">
      <option value="year 1">year 1</option>
      <option value="year 2">year 2</option>
      <option value="year 3">year 3</option>
    </select>
    </div>
    </form>
    

    when form submits you can get the value of selected option using $_POST['selectoptionname']

    0 讨论(0)
  • 2021-01-21 05:31

    put it in a form , then use $_POST['select']

    0 讨论(0)
  • 2021-01-21 05:39

    in somephpfile.php

    $selected = $_POST['somename'];
    

    html

     <form action="somephpfile.php" method="post"> 
        <div id="select">
        <select class="select">
        <select name="somename"> <!-- you missed this -->
          <option value="year 1">year 1</option>
          <option value="year 2">year 2</option>
          <option value="year 3">year 3</option>
        </select>
        </div>
        </form>
    
    0 讨论(0)
  • 提交回复
    热议问题