cancel
Showing results for 
Search instead for 
Did you mean: 

PHP Parser error

ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

PHP Parser error

Hello,
I couldn't get a simple php include to work, so I went back to basics and looked at the php help section on plusnet and copied and pasted this simple php example:
<html>
<head>
<?php
// A comment can be inserted like this
// Here we designate some variables
$bgcolor = "green";
$textcolor = "white";
?>
<title>Another PHP example</title>
</head>
 <body <?php print "bgcolor='$bgcolor' text='$textcolor';?>>
 <h3>Behold, a PHP enabled page :-)</h3>
 </body>
</html>

I uploaded it to my cgi space as test.php, changed permissions to 755 then opened it in a browser and got this error:
Quote
Parse error: parse error, unexpected $ in /share/storage/03/**/********/**/test.php  on line 15

Any ideas? I've been able to get a simple email contact form to work though.
Many thanks.
2 REPLIES 2
Ben_Brown
Grafter
Posts: 2,839
Registered: ‎13-06-2007

Re: PHP Parser error

Looks like a double quote missing. The line:
<body <?php print "bgcolor='$bgcolor' text='$textcolor';?>>

should be:
<body <?php print "bgcolor='$bgcolor' text='$textcolor';" ?>>

Although this way of styling webpages is a bit out of date, it's generally better to separate content and style using XHTML and CSS or similar, but the example serves as a very basic hello world type thing.
A good place to start with PHP is http://uk.php.net/manual/en/tutorial.firstpage.php
ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Re: PHP Parser error

Thanks a lot Ben. I've just realized why my include didn't work. I hadn't changed the extension from html to php.