tags:

views:

194

answers:

4

Hi,

I am new to php and trying out this tutorial at :

http://css-tricks.com/php-for-beginners-building-your-first-simple-cms/

Unfortunately I am getting the following error and can't seem to track down the reason:

Parse error: syntax error, unexpected T_PUBLIC in ../simpleCMS.php on line 56

My code for simpleCMS.php is as is in the tutorial link above.

FYI, my line 56 is the following line of code in simpleCMS.php

    public function display_admin() {

Above this line is public function display_public()

Can anyone possibly see what I could be doing wrong and again, my code is the same code from the tutorial website and have downloaded the files that came with it?

Hoping someone can point me in the right direction.

Furthermore, I am using Mac OS X MAMP to run my Apache/MySQL Server locally. My other question is, when I using the following command:

mysql_connect($this->host,$this->username,$this->password) 

is my hostname 'localhost' alone or do I also have to include port alongside the localhost?

Thanks again.

+4  A: 

Either line 55 has an error, missing a semi-colon or something that's making the next line choke, or you could be using a super old version of php which doesn't support classes though I would expect that to hose earlier on.

The public keyword can only be used in the class context in php, maybe that gives you a clue.

As for mysql_connect, it will assume the port 3306 unless you specify something else, having 'localhost' is usually enough.

Chuck Vose
YI, based on phpInfo I am running PHP Version 5.2.11. Also, based on my MySQL, my port seems to be 8889, do I then need to use Localhost:8889 ?
tonsils
@tonsils: yes, the format is 'hostname:port' See: http://php.net/manual/en/function.mysql-connect.php for more info
webbiedave
+1  A: 

Make sure all your braces are closed: { ... }

'localhost' should work fine for the DB

Scott Saunders
+1  A: 

Could it be that you're trying to run a PHP 5 script on PHP 4?

It's unlikely, but maybe worth checking.

As for your 2nd question (you should make that a separate question normally by the way, so others can find it later) if your port is the default 3306 (it probably is) then no, you don't need to specify the port number.

Pekka
A: 

MySQL treats "localhost" as special, and will assume you want to use the local UNIX-domain socket to connect, even if you want to connect via TCP. If you want to force a TCP connection, then use '127.0.0.1:3306' instead.

Marc B
Hi Marc, what does it mean then when my phpInfo says that the port for MySQL is 8889? I don't seem to see any 3306 port?
tonsils
Just means that your MySQL install's not on the default port (3306). No big deal, just use the 8889 for your connections instead.
Marc B