2011-05-13 56 views
1

嘗試執行php文件時,在本地MAMP服務器上獲取HTTP錯誤500。MAMP:來自PHP文件的HTTP錯誤500

所有我的其他網頁將運行,但這一個不會,所以我想這可能是與PHP的設置?

<?php 

// User.class.php 

require_once 'DB.class.php'; 

class User { 

    public $id; 
    public $username; 
    public $hashedPassword; 
    public $email; 
    public $joinDate; 

    // Takes an associative array with the DB row as an argument. 

    function __construct($data) { 

     $this->id = (isset($data['id'])) ? $data['id'] : ""; 
     $this->username = (isset($data['username'])) ? $data['username'] : ""; 
     $this->hashedPassword = (isset($data['password'])) ? $data['password'] : ""; 
     $this->email = (isset($data['email'])) ? $data['email'] : ""; 
     $this->joinDate = (isset($data['join_date'])) ? $data['join_date'] : ""; 

    } 

    public function save($isNewUser = false) { 

     $db = new DB(); 

     // Update already registered user. 
     if (!$isNewUser) { 

      $data = array(
       "username" => "'$this->username'"; 
       "password" => "'$this->hashedPassword'"; 
       "email" => "'$this->email'"; 
      ); 

      $db->update($data, 'users', 'id = '.$this->id); 

     } 

     // Register new user. 
     else { 

      $data = array(
       "username" => "'$this->username'"; 
       "password" => "'$this->hashedPassword'"; 
       "email" => "'$this->email'"; 
       "join_date" => "'".date("Y-m-d H:i:s", time())."'" 
      ); 

      $this->id = $db->insert($data, 'users'); 
      $this->joinDate = time(); 

     } 

     return true;  

    } 

} 

?> 

PHP錯誤日誌:

[13-May-2011 23:58:28] PHP Parse error: syntax error, unexpected ';', expecting ')' in /Applications/MAMP/htdocs/Project/classes/User.class.php on line 35 
+1

它說你的Apache error.log是500錯誤的原因是什麼?如果你不明白它告訴你什麼,請把它粘貼到你原來的問題中...... – 2011-05-13 23:12:14

回答

3

也許是因爲你已經用分號結束的數組值時,它應該是逗號:

$data = array(
       "username" => "'$this->username'"; 
       "password" => "'$this->hashedPassword'"; 
       "email" => "'$this->email'"; 
       "join_date" => "'".date("Y-m-d H:i:s", time())."'" 
      ); 

應該是:

$data = array(
       "username" => $this->username, 
       "password" => $this->hashedPassword, 
       "email" => $this->email, 
       "join_date" => date("Y-m-d H:i:s", time()) 
      ); 
+0

菜鳥的錯誤,謝謝。 – ritch 2011-05-13 23:20:32

2

帶有分號的陣列應該注意在PHP中發生致命錯誤,而不是500內部服務器錯誤。

+0

這兩個不是相互排斥的。當PHP發出致命錯誤時,Apache將發送500內部服務器錯誤。 – JJJ 2011-12-18 15:40:04

+1

煩人的是,這隻發生在MAMP。在WAMP中,它會執行一個實際的PHP錯誤,但在MAMP中,它始終會執行一個令人討厭的500錯誤,因爲我必須去錯誤日誌查看錯誤。 – Nathan 2012-05-17 23:24:30