【问题标题】:MAMP: HTTP Error 500 from PHP fileMAMP:来自 PHP 文件的 HTTP 错误 500
【发布时间】:2011-05-13 23:03:09
【问题描述】:

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

【问题讨论】:

  • 在您的 Apache error.log 中说什么是 500 错误的原因?如果您不明白它在告诉您什么,请将其粘贴到您的原始问题中...

标签: php apache mamp


【解决方案1】:

可能是因为您的数组值应该是逗号时以分号结尾:

$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())
            );

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 这两者并不相互排斥。当 PHP 抛出致命错误时,Apache 将发送 500 Internal Server Error。
    • 令人讨厌的是,这只发生在 MAMP 中。在 WAMP 中它会出现一个实际的 PHP 错误,但在 MAMP 中它总是会出现 500 错误,这很烦人,因为我必须转到错误日志才能看到错误。
    猜你喜欢
    • 2017-06-07
    • 2021-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 2013-10-30
    • 2016-05-06
    • 1970-01-01
    相关资源
    最近更新 更多