krysco Posted November 13, 2008 Share Posted November 13, 2008 So I downloaded this book to learn how to use PHP and MySQL to make database apps. I'm a pretty experienced HTML programmer and I want to learn a scripting language. I'm working on a Mac Pro with Ubuntu Desktop (Hardy Heron Release) with Apache2, MySQL (not sure which version), and PHP5 all set up and configured correctly. The first lesson in the book was to make a very simple guestbook, and of course I got stuck. I followed along writing out all the code by hand using gedit in Ubuntu. When I was done and went to view my work in Firefox I got the following message: Parse error: syntax error, unexpected '<' in /var/www/guestbook.php on line 8 I can't for the life of me figure out where this "unexpected < is". I've been over the code a million times and I can't find any that are extra. Can anybody help? <? mysql_connect("localhost", "root", "catch2@") or die ("Could not connect to database"); mysql_select_db("guestbook") or die ("Could not select database"); <form action="myscript.php"> <input type="text" name="surname"> <input type="submit" name="submit" value="submit"> </form> <h2>Sign my Guest Book!!!</h2> <form method=post action="create_entry.php"> <b>Name:</b> <input type=text size=40 name=name> <br> <b>Location:</b> <input type=text size=40 name=location> <br> <b>Email:</b> <input type=text size=40 name=email> <br> <b>Home Page URL:</b> <input type=text size=40 name=url> <br> <b>Comments:</b> <textarea name=comments cols=40 rows=4 wrap=virtual></textarea> <br> <input type=submit name=submit value="Sign!"> <input type=reset name=reset value="Start Over"> </form> ?> Quote Link to comment https://forums.phpfreaks.com/topic/132567-parse-error-syntax-error-unexpected/ Share on other sites More sharing options...
premiso Posted November 13, 2008 Share Posted November 13, 2008 You have html inside the PHP tags. Why are you attempting to connect to a database here? I do not see a spot where you use it on this page? <?php mysql_connect("localhost", "root", "catch2@") or die ("Could not connect to database"); mysql_select_db("guestbook") or die ("Could not select database"); ?> <form action="myscript.php"> <input type="text" name="surname"> <input type="submit" name="submit" value="submit"> </form> <h2>Sign my Guest Book!!!</h2> <form method=post action="create_entry.php"> <b>Name:</b> <input type=text size=40 name=name> <br> <b>Location:</b> <input type=text size=40 name=location> <br> <b>Email:</b> <input type=text size=40 name=email> <br> <b>Home Page URL:</b> <input type=text size=40 name=url> <br> <b>Comments:</b> <textarea name=comments cols=40 rows=4 wrap=virtual></textarea> <br> <input type=submit name=submit value="Sign!"> <input type=reset name=reset value="Start Over"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/132567-parse-error-syntax-error-unexpected/#findComment-689326 Share on other sites More sharing options...
krysco Posted November 13, 2008 Author Share Posted November 13, 2008 honestly.....i dunno. i'm just following along in the book. from what i understood html tags were allowed to be inside the php code, is that untrue? should i close the php tags before each html tag? ok i tried your code and it worked perfectly. just so that you don't think i'm nuts the book has the php closing tag at the end of the entire page and i guess that's not the way to do it. there wasn't any <HTML> or </HTML> in there at all. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/132567-parse-error-syntax-error-unexpected/#findComment-689337 Share on other sites More sharing options...
revraz Posted November 13, 2008 Share Posted November 13, 2008 Doesn't have to have the HTML tags in there. Also, the book may be having you do this and then reuse the code later to do MySQL querries. And yes you can have HTML inside of PHP code, you just have to use ECHO or PRINT to display it. Quote Link to comment https://forums.phpfreaks.com/topic/132567-parse-error-syntax-error-unexpected/#findComment-689353 Share on other sites More sharing options...
Mchl Posted November 13, 2008 Share Posted November 13, 2008 And yes you can have HTML inside of PHP code, you just have to use ECHO or PRINT to display it. Or close ?> php tags and <?php reopen them after. Which is easier if this part of HTML doesn't use any variables (and it doesn't). Quote Link to comment https://forums.phpfreaks.com/topic/132567-parse-error-syntax-error-unexpected/#findComment-689356 Share on other sites More sharing options...
revraz Posted November 13, 2008 Share Posted November 13, 2008 Yep, which was already stated, but I was answering his question.. "from what i understood html tags were allowed to be inside the php code, is that untrue? " And yes you can have HTML inside of PHP code, you just have to use ECHO or PRINT to display it. Or close ?> php tags and <?php reopen them after. Which is easier if this part of HTML doesn't use any variables (and it doesn't). Quote Link to comment https://forums.phpfreaks.com/topic/132567-parse-error-syntax-error-unexpected/#findComment-689362 Share on other sites More sharing options...
Mchl Posted November 13, 2008 Share Posted November 13, 2008 Yeah... misunderstood what you've written. Quote Link to comment https://forums.phpfreaks.com/topic/132567-parse-error-syntax-error-unexpected/#findComment-689363 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.