Jump to content

Parse error: syntax error, unexpected '<' in /var/www/guestbook.php on line 8


Recommended Posts

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>
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/132567-parse-error-syntax-error-unexpected/
Share on other sites

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>

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!

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.

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).

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.