ok im new to PHP and sortof need to learn the basics for my job and i got the oreily PHP 5 book and in some of the examples i keep getting a parse error. here is an example

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php
//Print a greeting if the form was submitted
if ($_POST['user']) {
  print "Hello, ";
//Print what was submitted in the form parameter called user
print $_POST['user'];
print "!";
 }
else {
 //otherwise, print the form
 print <<<_HTML_
 <form method="post" action="$SERVER[PHP_SELF]">
 Your Name: <input type="text" name="user">
 <br/>
 <input type="submit" value="Say Hello">
 </form>
 _HTML_;
 }
 ?>
</body>
</html>

and it says there is a parse error on the line with the </html>. I cant seem to figure what is wrong it is exactly like the book's example.

Recommended Answers

All 2 Replies

I fixed the problem here is the updated code if you would like to compare

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php
//Print a greeting if the form was submitted
if ($_POST['user']) {
  print 'Hello, ';
//Print what was submitted in the form parameter called user
print $_POST['user'];
print "!";
}
else {
//otherwise, print the form
print <<<_HTML_
<form method="post" action="$SERVER[PHP_SELF]">
Your Name: <input type="text" name="user">
<br/>
<input type="submit" value="Say Hello">
</form>
_HTML_;
}
?>
</body>
</html>

i think it was the double quotes instead of the single in 'hello, '

I had the exact same problem from the same book! The solution was to replace the double-quotes with single-quotes. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.