Page 1 of 1

I have run into a snag

Posted: Sun Jun 06, 2010 10:44 am
by Strider64
I'm getting parse errors no matter what code I type, I'm trying to learn PHP by following the examples in the book "PHP, MySQL & Javascript" by Robin Nixon.
I typed in the following code:

Code: Select all

<?php
$object = new User;
print_r($object);

class User
{
	public $name, password;
	
	function save_user()
	{
		echo "Save User code goes here";
	}
}

?>
and get this:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/11/d329291176/htdocs/test.php on line 7

I even tried good code from using an example from http://php.net/, so I think I have messed up my PHP on my server? I don't know I'm getting more gray hair and I already have to much of it to begin with. :lol: If anyone can steer me in the direction of fixing this, so I can stop banging my head against the wall. :banghead:

It would be very much appreciated.

Best Regards,
John

P.S. I don't know if this is the correct Category, but if not I apologize.

Re: I have run into a snag

Posted: Sun Jun 06, 2010 10:50 am
by Benjamin

Code: Select all

public $name, password;
Should be:

Code: Select all

public $name, $password;
You may want to look into an editor, such as Eclipse, which will notify you syntax errors as you type. (Eclipse PDT)

Re: I have run into a snag

Posted: Sun Jun 06, 2010 11:13 am
by Strider64
Thanks for the quick replay and I'll definitely look into Eclipse editor. However, it still didn't not fix the error - revised code :

Code: Select all

<?php
$object = new User;
print_r($object);

class User
{
	public $name, $password;
	
	function save_user()
	{
		echo "Save User code goes here";
	}
}

?>
Totally baffling....

Re: I have run into a snag

Posted: Sun Jun 06, 2010 11:25 am
by Benjamin
There are no parse errors in that code, unless you are using PHP 4.

Re: I have run into a snag

Posted: Sun Jun 06, 2010 11:46 am
by Strider64
I figured it out - it was because my server was using PHP4 and my ISP said to add this the following:

AddType x-mapp-php5 .php .php4

to the .htaccess file .... works like a charm....thanks for the help...now I go color my hair back to my original color. :lol:

I don't understand my web server host provider for following says

You may choose to simply name the script with the .php5 file extension if there are only a few scripts that require PHP5. If you don't want to rename all your scripts to .php5, you can do the create a .htaccess file (or edit the existing .htaccess file, if you already have one). You can create this file using a text editor such as Notepad, WordPad, vi, nano, etc. and place the following line in the text file:

There most be a logical reason on their end why they want to do it that way, but I wouldn't know why. However, I don't care as long as I got it to work!

Re: I have run into a snag

Posted: Mon Jun 07, 2010 1:55 am
by Doug G
PHP4 is pretty old. I'd be looking for a host that offers php 5+ myself :)

Re: I have run into a snag

Posted: Mon Jun 07, 2010 6:27 am
by Strider64
My host offers PHP 5 it just not the default, which you would think it would be? It's not a big deal unless your just learning PHP then it can be frustrating. However, it's a great way to learn that things don't always go as plan. :lol: