dooso0594 2017-03-05 06:06
浏览 33
已采纳

从mysli_fetch_array中获取选定的值并输出

I have a problem to get a selected value and output it. Example i select 1001 from dropdown. When I echo it always return the value from first row wish is 1002.

this my code edit.php

<form id="form" action="test.php" method="post">
    <?php
    echo "<select name=\"Reservation ID\" form=\"form\">";
    while ($row = mysqli_fetch_array($result)) 
    {
        $gg = $row['reserve_id'];
         echo "<option value='" . $gg . "' name=\"reserve_id\">" . $gg . "</option>";
    }
    echo "</select>";
    $_SESSION['reserve'] = $gg;
    ?>
    <input type="submit" name="form" value="Submit">
</form>

this is code from test.php

$y = $_SESSION['reserve'];
if(isset($_POST['form']))
{
  echo $y;
}

dropdown value

List of reservation ID

  • 写回答

1条回答 默认 最新

  • douchen9569 2017-03-05 06:14
    关注

    This is of course a duplicate question.

    EDIT:

    After loop execution $gg will point to the last value in the list (1002 in this case). I believe you are trying to access the value of the user-chosen <option> of the <select> which can be done by:

    In edit.php:

    <form id="form" action="test.php" method="post">
        <?php
            echo "<select name=\"Reservation_ID\" form=\"form\">";
            while ($row = mysqli_fetch_array($result)) 
            {
                $gg = $row['reserve_id'];
                echo "<option value='" . $gg . "' name=\"reserve_id\">" . $gg . "</option>";
            }
            echo "</select>";
            $_SESSION['reserve'] = $gg;//this is not required to get <select> value, but may be relevant to what you are doing otherwise
        ?>
        <input type="submit" name="form" value="Submit">
    </form>
    

    In test.php:

    $y = $_SESSION[''];//this is not required to get <select> value, but may be relevant to what you are doing otherwise
    if(isset($_POST['form']))
    {
        echo $_POST['Reservation_ID'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?