$ _POST的未定义索引,即使已定义

时间:2020-05-16 07:31:32

标签: php html forms post undefined

因此,我使用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()包围变量。我已经尝试过围绕ifset进行if块测试。没有任何办法可以解决此问题。我不知道为什么这行不通。有人可以帮忙吗?谢谢

整个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"]);

1 个答案:

答案 0 :(得分:0)

这个问题似乎很奇怪,但是一个很好的起点是回显服务器似乎正在看到的内容(完全结构化)。可以这样做:

echo "<pre>";
print_r($_POST);
echo "</pre>";

并且看到您正在使用enctype =“ multipart / form-data”,您还可以转储$ _FILES。但是我感觉这可能是两件事之一:动作场或反斜杠。对于最后一种选择,为什么不在清洁之前选择它们,然后再清洁。对于第一个选项,是否可以将操作字段更改为显式本地:

<form action="validation.php" method="post" enctype="multipart/form-data">
相关问题