此错误出现在一个特定元素上。所有其他元素都可以获取这些索引,但不能获得这些索引。它以前工作过,但现在完全崩溃了;我试图撤消一些变化,但没有真正帮助,我想知道为什么会发生这种情况。
以下是出现的错误:http://i.imgur.com/FIkHJop.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();
答案 0 :(得分:0)
只需刷新页面即可进行测试。
要尝试的一件事是清除浏览器缓存,转到调用register.php的页面,填写一些测试信息,最后点击注册。