943,626 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2378
  • PHP RSS
Jul 10th, 2006
0

Parse error in code

Expand Post »
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 [php]<!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>[/php]
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.
Last edited by mikeandike22; Jul 10th, 2006 at 10:33 pm.
Similar Threads
Reputation Points: 33
Solved Threads: 19
Nearly a Posting Virtuoso
mikeandike22 is offline Offline
1,496 posts
since May 2004
Jul 10th, 2006
0

Re: Parse error in code

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

PHP Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <title>Untitled Document</title>
  6. </head>
  7. <body>
  8. <?php
  9. //Print a greeting if the form was submitted
  10. if ($_POST['user']) {
  11. print 'Hello, ';
  12. //Print what was submitted in the form parameter called user
  13. print $_POST['user'];
  14. print "!";
  15. }
  16. else {
  17. //otherwise, print the form
  18. print <<<_HTML_
  19. <form method="post" action="$SERVER[PHP_SELF]">
  20. Your Name: <input type="text" name="user">
  21. <br/>
  22. <input type="submit" value="Say Hello">
  23. </form>
  24. _HTML_;
  25. }
  26. ?>
  27. </body>
  28. </html>

i think it was the double quotes instead of the single in 'hello, '
Last edited by mikeandike22; Jul 10th, 2006 at 10:41 pm.
Reputation Points: 33
Solved Threads: 19
Nearly a Posting Virtuoso
mikeandike22 is offline Offline
1,496 posts
since May 2004
Apr 18th, 2008
0

Re: Parse error in code

I had the exact same problem from the same book! The solution was to replace the double-quotes with single-quotes. Thanks!
Reputation Points: 10
Solved Threads: 1
Newbie Poster
gcardella is offline Offline
1 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: data pass using submit button
Next Thread in PHP Forum Timeline: Parse error: syntax error, unexpected T_STRING in E:\Program Files\wamp\www\practice\





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC