【发布时间】: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() 函数尚未涵盖。所以之前回答的问题对个人知识很有帮助,但并不完全适用于我目前的情况。不过,感谢您提供的良好链接。