Very simple problem book code doesnt function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pablocullen
Forum Newbie
Posts: 2
Joined: Sun Nov 20, 2005 7:01 am

Very simple problem book code doesnt function

Post by pablocullen »

Hello

This is my first post in these forums, i am a newbie (but everyone is at some stage) i have what i believe is a simple problem yet i cant find an explanation.
I got a book "Mysql/PHP Database Applications by Jay Greenspan and Brad Bulger"
Now ive started studying this book and was givin sample code to write a simple guestbook application.

Below is the code word for word letter for letter from the book.

Code: Select all

<?php
include('dbconnect.php');

if ($submit == 'Sign!')
{
	$query = 'insert into guestbook
		(name,location,email,url,comments) values
		('$name', '$location','$email','$url','$comments')'
	;
	mysql_query($query) or
			die (mysql_error());
	?>
	<h2>Thanks!!</h2>
	<h2><a href="view.php">View My Guest Book!!!</a></h2>

	<?php
	}
	else
	{
		include('sign.php');
	}
	?>
Now, i am getting an error stated below:

Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\school\create_entry.php on line 8

Can anyone help

I imagine that it is quite a simple problem however i do not have the knowledge to solve it.

Thanks in advance
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

The insert string is put into single quotes but also contains unescaped single quotes within the string.

just use double quotes to outline the string

This should not happen in a book but unfortunately happens all the time
pablocullen
Forum Newbie
Posts: 2
Joined: Sun Nov 20, 2005 7:01 am

Post by pablocullen »

By god man i think youve done it!!!!!

Thank you very much you saved me a few euros on headache tablets.

Thanks for the quick and accurate reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Try posting in [syntax=php][/syntax] next time... you'd of seen the problem immediatly if you had ;)
Post Reply