php not working

Associate
Joined
19 Jul 2006
Posts
1,847
experimenting with include statements
heres a simple one for you got this code
Code:
<body>
<? php include("v.php"); 
echo $username;
?>
</body>
</html>

in the php file called v (for variables) i have a variable called username
Code:
<body>
<? php
//Define Variables
$username=Matthew;
$password=password1;
$greeting="Hello";
//send username to browser
echo "Username:$username<br>Password:$password";
?>
</body>
</html>

looking at the book its correct and at how w3schools dose it.
But i get a
Parse error: syntax error, unexpected T_INCLUDE in C:\xampplite\htdocs\passwordsite\include.php on line 8

Cant see what it dont work
 
Are you adding the spaces between <? and php? If so, remove them.

Also, quote your string literals—it should be:

Code:
$username = 'Matthew';

or:

Code:
$username = "Matthew";

You'll get a warning (notice?) if you try and use an unquoted string, because PHP thinks it's a constant.
 
Back
Top Bottom