【问题标题】:Get selected value and display to another page获取选定的值并显示到另一个页面
【发布时间】:2019-11-27 23:50:48
【问题描述】:

此选择将显示用户列表及其 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>

【问题讨论】:

  • 你应该把select元素放到form中。
  • @chaska,对不起,这没有多大帮助:(
  • 将action="destinationpage.php" 添加到表单并在destinationpage.php 中使用&lt;?php var_dump( $_REQUEST[] )

标签: php html oracle


【解决方案1】:

您应该将表单方法设置为get 而不是post。您还需要为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']

【讨论】:

  • 表单应该放在哪里很重要?她可以在 $stid 之后开始吗?
  • form 必须包装由$stid 代码块回显的选择元素。
  • 我把这个放在哪里 :send.php?send=send&id=
  • 你不需要在任何地方添加它。这只是表单将发送给您的 URL 的一个示例。
  • 我正在考虑从哪里开始
    因为 $stid= oci_parce,这不是代码的开始
猜你喜欢
  • 2018-08-03
  • 1970-01-01
  • 2014-10-27
  • 1970-01-01
  • 2021-09-29
  • 2021-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多