0

This error appears at one specific element. All the other elements can get those indexes, but not this one. It worked before, but now it completely broke; I tried to undo some changes but didn't really help and I'm wondering why this really happens.

Here are the errors that appear: https://i.stack.imgur.com/JWlK4.png And the code:

<?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();
Milenchy
  • 1
  • 7

1 Answers1

0

Post issues can happen when you're testing by simply refreshing the page.

One thing to try would be to clear your browser cache, go to the page that would call register.php, fill out some test information, and finally click register.

Anthony
  • 107
  • 5