【问题标题】:php collecting/displaying form data with $_POST method [duplicate]php 使用 $_POST 方法收集/显示表单数据
【发布时间】:2017-02-21 20:28:30
【问题描述】:

我正在尝试从文本框、径向线、复选框等中收集数据,然后使用我的 display_results.php 显示它们。然而,我一直遇到一个烦人的问题error undefined index,但我认为我确实使用变量 $num 定义了索引。我没有被指示只使用 isset() 函数 $_POST 因为表单使用表单 POST 方法。有人可以指出为什么没有isset()变量没有被索引和显示吗?

感谢您的帮助!

<?php
// get the data from the form
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);

// get the rest of the data for the form
$password = filter_input(INPUT_POST, 'password');

$num = filter_input(INPUT_POST, 'num');

$heard_from = filter_input(INPUT_POST, 'heard_from' ); ?>

<!DOCTYPE html>
<html>
<head>
    <title>Account Information</title>
    <link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
    <main>
        <h1>Account Information</h1>

        <label>Email Address:</label>
        <span><?php echo htmlspecialchars($email); ?></span><br>

        <label>Password:</label>
        <span><?php echo $_POST['password']?></span><br>

        <label>Phone Number:</label>
        <span><?php echo $_POST['num']?></span><br>

        <label>Heard From:</label>
        <span><?php echo $_POST['heard_from']?></span><br>
      
    </main>
</body>
</html>

【问题讨论】:

  • 我被要求用我们目前所学的内容进行编码,而 isset() 函数尚未涵盖。所以之前回答的问题对个人知识很有帮助,但并不完全适用于我目前的情况。不过,感谢您提供的良好链接。

标签: php forms post display


【解决方案1】:

我假设您有 3 个或更多页面(表单、第一个 sn-p、第二个 sn-p)并且您将数据从第一个 sn-p 传递到第二个 sn-p,您在其中重新回显原始 POST 数据

echo $_POST['num']

但您应该回显过滤后的输入变量

echo $num

【讨论】:

  • 所以我应该把 echo $variable 放在 标签之间?
猜你喜欢
  • 1970-01-01
  • 2019-09-20
  • 2013-08-16
  • 2021-04-18
  • 2015-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-26
相关资源
最近更新 更多