php - 获取选定的值并显示到另一个页面
问题描述
此选择将显示用户列表及其 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>
解决方案
您应该将表单方法设置为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']
推荐阅读
- python - 创建熊猫数据框时将“名称”属性添加到行名和列名
- java - 获取一个知道其名称的按钮
- ios - '() -> 绑定目标
' 不能转换为 '(Bool) -> BindingTarget ' - security - 如何从稀疏数组中生成唯一且随机的 ID?
- node.js - 如何用猫鼬处理动态数据库?
- graphql - 在 GraphQL 上按 2 个或更多字段查询
- node.js - 我可以将 Node Pug 模板移动到 dist 文件夹并动态加载内容吗?
- proxy - 通过使用 raspi 作为代理网关,将 win-10 上的 VNC 查看器设置到远程桌面 (Win-10)
- javascript - 如何在Javascript中的特定字符串+斜杠之后获取字符串?
- java - 如何获取带有 bytea 类型 id 列的表?