Page 1 of 1

Very simple problem book code doesnt function

Posted: Sun Nov 20, 2005 8:13 am
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

Posted: Sun Nov 20, 2005 8:16 am
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

Posted: Sun Nov 20, 2005 8:20 am
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

Posted: Sun Nov 20, 2005 12:20 pm
by John Cartwright
Try posting in [syntax=php][/syntax] next time... you'd of seen the problem immediatly if you had ;)