即使定义了 $_POST 的未定义索引
Undefined Index with $_POST even when defined
所以我正在使用 php 制作一个登录表单,每次提交时我都会收到未定义的索引错误。这是我的表格:
<form action="website.net/validation.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Username</label>
<input type="text" maxlength="255" placeholder="Username" name="user" class="form-control" required />
</div>
<div class="form-group">
<label>Password</label>
<input type="password" maxlength="255" placeholder="Password" name="password" class="form-control" required />
</div>
<hr class="my-4">
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck1" name="remember" value="yes">
<label class="custom-control-label" for="customCheck1">Remember Me</label>
</div>
</div>
<br>
<p class="lead">
<button type="submit" class="btn btn-primary btn-lg">Login</button>
</p>
</form>
这是 php:
$name = stripslashes($_POST["user"]);
$pass = stripslashes($_POST["password"]);
这显然只是意味着我拼写错误或未设置值,对吗?错误的。我检查了 html 和 php 中的所有拼写,我还检查了 var_dump($_POST["user"]);
并打印出用户名。表单元素是 必需的 ,因此不能不设置它们。我试过用 htmlentities() 包围变量。我试过将它们包围在 if then 块中以测试 ifset。没有什么能解决这个问题。我不知道为什么这不起作用。有人可以帮忙吗?谢谢
整个 php 直到错误:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
var_dump($_POST);
$name = stripslashes($_POST["user"]);
$pass = stripslashes($_POST["password"]);
这个问题看起来很奇怪,但一个很好的起点是回应服务器似乎看到的内容(完全结构化)。可以这样做:
echo "<pre>";
print_r($_POST);
echo "</pre>";
并且看到您正在使用 enctype="multipart/form-data",您也可以转储 $_FILES。但我有一种感觉,它可能是两件事之一:行动领域或 stripslashes。对于最后一个选项,为什么不在清洁之前先摘下它们,然后再清洁。对于第一个选项,您能否将操作字段更改为明确本地:
<form action="validation.php" method="post" enctype="multipart/form-data">
所以我正在使用 php 制作一个登录表单,每次提交时我都会收到未定义的索引错误。这是我的表格:
<form action="website.net/validation.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Username</label>
<input type="text" maxlength="255" placeholder="Username" name="user" class="form-control" required />
</div>
<div class="form-group">
<label>Password</label>
<input type="password" maxlength="255" placeholder="Password" name="password" class="form-control" required />
</div>
<hr class="my-4">
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck1" name="remember" value="yes">
<label class="custom-control-label" for="customCheck1">Remember Me</label>
</div>
</div>
<br>
<p class="lead">
<button type="submit" class="btn btn-primary btn-lg">Login</button>
</p>
</form>
这是 php:
$name = stripslashes($_POST["user"]);
$pass = stripslashes($_POST["password"]);
这显然只是意味着我拼写错误或未设置值,对吗?错误的。我检查了 html 和 php 中的所有拼写,我还检查了 var_dump($_POST["user"]);
并打印出用户名。表单元素是 必需的 ,因此不能不设置它们。我试过用 htmlentities() 包围变量。我试过将它们包围在 if then 块中以测试 ifset。没有什么能解决这个问题。我不知道为什么这不起作用。有人可以帮忙吗?谢谢
整个 php 直到错误:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
var_dump($_POST);
$name = stripslashes($_POST["user"]);
$pass = stripslashes($_POST["password"]);
这个问题看起来很奇怪,但一个很好的起点是回应服务器似乎看到的内容(完全结构化)。可以这样做:
echo "<pre>";
print_r($_POST);
echo "</pre>";
并且看到您正在使用 enctype="multipart/form-data",您也可以转储 $_FILES。但我有一种感觉,它可能是两件事之一:行动领域或 stripslashes。对于最后一个选项,为什么不在清洁之前先摘下它们,然后再清洁。对于第一个选项,您能否将操作字段更改为明确本地:
<form action="validation.php" method="post" enctype="multipart/form-data">