2

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
1
  • 1
    What does it say in your Apache error.log is the reason for the 500 error? Please paste it into your original question if you don't understand what it's telling you...
    – AJ.
    May 13, 2011 at 23:12

2 Answers 2

3

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())
            );
0
2

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

2
  • Those two aren't mutually exclusive. Apache will send 500 Internal Server Error when PHP throws a fatal error.
    – JJJ
    Dec 18, 2011 at 15:40
  • 1
    The annoying thing is that this only happens MAMP. In WAMP it does an actual PHP error, but in MAMP it always does a 500 error which is annoying because I have to go to the error log to see the error.
    – Nathan
    May 17, 2012 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.