MAMP:PHP 文件中的 HTTP 错误 500

发布于 2024-11-07 03:56:41 字数 1928 浏览 0 评论 0原文

尝试执行 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

Getting HTTP Error 500 on a local MAMP server when trying to execute a php file.

All my other pages will run however this one will not so I'm thinking that it maybe something to do with the php settings?

<?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 Error Log:

[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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余生再见 2024-11-14 03:56:41

也许是因为数组值以分号结尾,而它应该是逗号:

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

Maybe because you have array values terminated with semi-colons when it should be commas:

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

should be:

$data = array(
                "username" => $this->username,
                "password" => $this->hashedPassword,
                "email" => $this->email,
                "join_date" => date("Y-m-d H:i:s", time())
            );
誰ツ都不明白 2024-11-14 03:56:41

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

An array with semi-colons should cause a Fatal Error in PHP, not a 500 Internal Server error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文