parse error

A

Anonymous

Guest
Hi,
i get an error message:
Parse error: parse error, unexpected T_VARIABLE in C:\Program Files\Apache Group\Apache2\htdocs\additem.php on line 3
when i try to run a PHP page. Anyone know wat's wrong with this?

here's the coding:
<? php
$name=$HTTP_POST_VARS['name'];
$location=$HTTP_POST_VARS['location'];
$email=$HTTP_POST_VARS['email'];
$url=$HTTP_POST_VARS['url'];
$comments=$HTTP_POST_VARS['comments'];
$submit=$HTTP_POST_VARS['submit'];

@ $db = mysql_pconnect('host', 'usr', 'pass');

if (!$db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}

mysql_select_db('guestbook');


if ($submit)
{
$query="insert into guestbook(name,location,email,url,comments)
values('".$name."','".$location."',
'".$email."','".$url."',
'".$comments."')";
mysql_query($query);

echo "<h2>Thanks!</h2>";
echo "<h2><a href="view.php">View My Guest Book!!!</a></h2>";
}
else
{
include("sign.php");
}
?>

thank you!
 
thanks,
i change that,but now i'm getting another error:
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\Program Files\Apache Group\Apache2\htdocs\additem.php on line 30
 
You have to escape quotation marks used within strings, because when PHP sees a quotation mark it assumes you're ending the string.

This is wrong (see how it's no longer part of the string):
PHP:
<?php
echo "<h2><a href="view.php">View My Guest Book!!!</a></h2>";
?>
This is right:
PHP:
<?php
echo "<h2><a href=\"view.php\">View My Guest Book!!!</a></h2>";
?>
This is better:
PHP:
<?php
echo '<h2><a href="view.php">View My Guest Book!!!</a></h2>';
?>

(By the way, please use the board's
PHP:
 tags around your code to make it more readable, like the above.)
 
Back
Top