2014-12-03 95 views
0

此錯誤出現在一個特定元素處。所有其他元素都可以得到這些索引,但不是這一個。它之前有效,但現在它完全破裂了;我試圖撤銷一些變化,但沒有真正幫助,我想知道爲什麼這真的發生。特定元素的「未定義索引」錯誤

這裏是出現了錯誤: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

郵政發行可當你通過簡單地刷新頁面測試發生。

有一件事要嘗試將清除您的瀏覽器緩存,去調用register.php,填寫一些測試信息,最後點擊註冊頁面。

+0

可悲的是它沒有工作 – Milenchy 2014-12-04 12:44:45