php collecting/displaying 使用 $_POST 方法的表单数据

php collecting/displaying form data with $_POST method

我正在尝试从文本框、径向线、复选框等收集数据,然后用我的 display_results.php 显示它们。然而,我一直遇到一个烦人的问题 error undefined index 但我认为我确实用我的变量 $num 定义了索引。我没有被指示仅使用 $_POST isset() 函数,因为该表单使用表单 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>

我假设您有 3 个或更多页面(表单、第一个代码段、第二个代码段)并且您将数据从第一个代码段传递到第二个代码段,其中您回应原始 POST数据

echo $_POST['num']

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

echo $num