MAMP:来自PHP文件的HTTP错误500

时间:2011-05-13 23:03:09

标签: php apache mamp

尝试执行php文件时,在本地MAMP服务器上获取HTTP Error 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

2 个答案:

答案 0 :(得分: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())
            );

答案 1 :(得分:2)

具有分号的数组应该在PHP中导致致命错误,而不是500内部服务器错误。