首页 > 解决方案 > 获取选定的值并显示到另一个页面

问题描述

此选择将显示用户列表及其 ID、fname 和 lname。怎么办,所以如果我从列表中选择用户,然后单击“发送”按钮,它将重定向到另一个页面,并在第二页中显示我选择的用户?

$stid = oci_parse($conn, "select user_id, fname,lname from users");
oci_execute($stid);

    echo "<select size = '5'>";

    while (($row = oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_NULLS))!= false) {
        echo "<option value=$row[user_id]>".$row['user_id'] . " " .$row['fname'] 
        . " " . $row['lname'] . "</option>";
    }

    echo "</select>";




<form method="post" action="send.php">

    <input type="submit" name="send" value="send">

</form>

标签: phphtmloracle

解决方案


您应该将表单方法设置为get而不是发布。您还需要给select元素一个name属性,以便发送它的值。

<form method="get" action="send.php">
<?php
$stid = oci_parse($conn, "select user_id, fname,lname from users");
    oci_execute($stid);
    echo "<select name='id' size = '5'>";
    while (($row = oci_fetch_array($stid,OCI_ASSOC+OCI_RETURN_NULLS))!= false){
        echo "<option value=$row[user_id]>".$row['user_id'] . " " .$row['fname'] . " " . $row['lname'] . "</option>";
    }echo "</select>";
?>
<input type="submit" name="send" value="send"></p>
</form>

提交表单会将您的浏览器发送至:

send.php?send=send&id=<id>

然后,send.php您可以从$_GET超全局中获取用户 ID。

$userId = $_GET['id']

推荐阅读