gpt4 book ai didi

php - 从 mysli_fetch_array 获取选定值并输出

转载 作者:行者123 更新时间:2023-11-29 10:58:45 25 4
gpt4 key购买 nike

我在获取选定值并将其输出时遇到问题。示例我从下拉列表中选择1001。当我回显时,它总是返回第一行希望的值是 1002

这是我的代码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>

这是来自test.php的代码

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

dropdown value

List of reservation ID

最佳答案

这当然是duplicate question .

编辑:

循环执行后$gg将指向列表中的最后一个值(本例中为 1002)。我相信您正在尝试访问用户选择的值 <option> <select>的可以通过以下方式完成:

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>

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'];
}

关于php - 从 mysli_fetch_array 获取选定值并输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42605087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com