特定元素处的“未定义索引”错误


"Undefined index" error at a specific element

此错误出现在一个特定元素上。所有其他元素都可以获取这些索引,但不能获取此索引。它以前有效,但现在完全坏了;我试图撤消一些更改,但没有真正的帮助,我想知道为什么会发生这种情况。

以下是出现的错误:https://i.stack.imgur.com/JWlK4.png和代码:

<?php
class User {
    public function __construct( $username, $password, $passwordRepeat, $email, $firstName, $familyName, $age, $sex, $question, $answer, $car ) {
        $this->username       = $username;
        $this->password       = $password;
        $this->passwordRepeat = $passwordRepeat;
        $this->email          = $email;
        $this->firstName      = $firstName;
        $this->familyName     = $familyName;
        $this->age            = $age;
        $this->sex            = $sex;
        $this->question       = $question;
        $this->answer         = $answer;
        $this->car            = $car;
    }
    public function savePicture( $profilePicture ) {
         /*do this later*/
    }
    public function saveUser() {
        $profiles = "profiles/$this->username.txt";
        if ($this->password !== $this->passwordRepeat) {
            require "register.html";
            echo "<p><strong>Passwords do not match! Please try again</strong></p>";
        } else if ( file_exists( $profiles ) ) {
            require "register.html";
            echo "<p><strong>Username already exists!</strong></p>";
        } else {
            $fp   = fopen( $profiles, "a+" );
            $save = $this->username . " , " . $this->password . " , " . $this->email . " , " . $this->firstName . " , " . $this->familyName . " , " . $this->age . " , " . $this->sex . " , " . $this->question . " , " . $this->answer . " , " . $this->car;
            fwrite( $fp, $save );
        }
    }
    public function printUser() {
        echo $this->username . " , " . $this->password . " , " . $this->email . " , " . $this->firstName . " , " . $this->familyName . " , " . $this->age . " , " . $this->sex . " , " . $this->question . " , " . $this->answer . " , " . $this->car;
    }
}
/*This is the problematic element. It worked before but then it broke for some reason. PHPStorm doesn't say anything*/
$user = new User( $_POST['username_register'], $_POST['password_register'], $_POST['password_repeat'], $_POST['email_register'], $_POST ['first_name_register'], $_POST ['last_name_register'], $_POST['age'], $_POST ['sex_register'], $_POST ['question_register'], $_POST ['answer_register'], $_POST['car'] );
/*----------------------*/
$user->saveUser();
$user->printUser();
当您

通过简单地刷新页面进行测试时,可能会发生帖子问题。

要尝试的一件事是清除浏览器缓存,转到将调用 register.php 的页面,填写一些测试信息,最后单击注册。