View Full Version : Parse error, unexpected T_VARIABLE


onigiri
12-20-2005, 06:41 AM
Here's the story this time: I went and learned SQL, decided to make a very simple blog script as a project, and now my index.php (the page that displays all the entries) is getting a parse error.

The code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Why are you looking here? The blog's down there.</title>

<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div align="center">
<div id="container">
<div id="image"><img src="winterdrop.jpg" alt="Header image" /></div>
<div class="main">
<?php

//connect to the database
require_once("config.php");

//gather the posts
$gather_posts = "SELECT entry, title, date_format(create_time, '%b %e %Y at %r') as fmt_create_time FROM entries order by create_time desc";
$gather_posts_res = mysql_query($gather_posts,$db) or die(mysql_error());

//what to do if there are posts or not
if (mysql_num_rows($gather_posts_res) < 1) {//there are no posts
$display_block = "Antibaseball has not posted";
} else {
//create the display string
while ($blog_info = mysql_fetch_array($gather_posts_res)) {
$entry_text = $blog_info['entry'];
$entry_title = $blog_info['title'];
$entry_create_tme = $blog_info['create_time'];

$display_block = "
<div class=post>
<span class=header>$post_title</span><p></p>
<span class=timestamp>$create_time</span><p></p>
$post_entry
</div><p></p><p></p>
}
?>
<p>
<?php
echo "$display_block";
?>
</div>
<div class="nav">Nav stuff</div>
</div>
</div>
</body>
</html>

putnamehere
12-20-2005, 06:53 AM
it normaly also gives the line witchs it's on? trhat would be helpful if we new what line it was on?

smiles2
12-20-2005, 08:18 AM
In this section, you have just one "

$display_block = "
<div class=post>
<span class=header>$post_title</span><p></p>
<span class=timestamp>$create_time</span><p></p>
$post_entry
</div><p></p><p></p>

Is it supposed to be like that?

Those T_Variable errors, in my experience, are
usually due to a missing closing quote or semicolon
BEFORE the line that is displayed.

onigiri
12-20-2005, 10:58 PM
Okay, I fixed that parse error by adding the missing quotations, like you said, smilies, but now I'm getting an "unexpected $end" parse error. My current code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Why are you looking here? The blog's down there.</title>

<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div align="center">
<div id="container">
<div id="image"><img src="winterdrop.jpg" alt="Header image" /></div>
<div class="main">
<?php

//connect to the database
require_once("config.php");

//gather the posts
$gather_posts = "SELECT entry, title, date_format(create_time, '%b %e %Y at %r') as fmt_create_time FROM entries order by create_time desc";
$gather_posts_res = mysql_query($gather_posts,$db) or die(mysql_error());

//what to do if there are posts or not
if (mysql_num_rows($gather_posts_res) < 1) {//there are no posts
$display_block = "Antibaseball has not posted";
} else {
//create the display string
while ($blog_info = mysql_fetch_array($gather_posts_res)) {
$entry_text = $blog_info['entry'];
$entry_title = $blog_info['title'];
$entry_create_tme = $blog_info['create_time'];

$display_block = "<div class='post'><span class='header'>$post_title</span><p></p><span class='timestamp'>$create_time</span><p></p>$post_entry</div><p></p><p></p>";
}
?>
<p>
<?php
echo "$display_block";
?>
</div>
<div class="nav">Nav stuff</div>
</div>
</div>
</body>
</html>

Douglas
12-20-2005, 11:33 PM
Try this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Why are you looking here? The blog's down there.</title>

<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div align="center">
<div id="container">
<div id="image"><img src="winterdrop.jpg" alt="Header image" /></div>
<div class="main">
<?php

//connect to the database
require_once("config.php");

//gather the posts
$gather_posts = "SELECT entry, title, date_format(create_time, '%b %e %Y at %r') as fmt_create_time FROM entries order by create_time desc";
$gather_posts_res = mysql_query($gather_posts,$db) or die(mysql_error());

//what to do if there are posts or not
if (mysql_num_rows($gather_posts_res) < 1) {//there are no posts
$display_block = "Antibaseball has not posted";
}
else {
//create the display string
while ($blog_info = mysql_fetch_array($gather_posts_res)) {
$entry_text = $blog_info['entry'];
$entry_title = $blog_info['title'];
$entry_create_tme = $blog_info['create_time'];

$display_block = "<div class='post'><span class='header'>$entry_title</span><p></p><span class='timestamp'>$entry_create_time</span><p></p>$entry_text</div><p></p><p></p>";
}
?>
<p>
<?php
echo $display_block;
?>
</div>
<div class="nav">Nav stuff</div>
</div>
</div>
</body>
</html>


You had some unset variables there, I fixed it, it may would, well it should :)

onigiri
12-20-2005, 11:56 PM
I'm still getting an "unexpected $end" parse error. :(

Douglas
12-21-2005, 12:02 AM
Think you could post the config file... maybe its in there ;)

onigiri
12-21-2005, 03:32 AM
Here's config.php:


<?php

//Database connection variables
$hostname = "domain.net";
$username = "some_blog";
$password = "pass";
$database = "some_blog";

//Connect to the database
$db = @mysql_connect("$hostname","$username","$password");
mysql_select_db("$database") or die("The database could not be connected to.");

?>

Douglas
12-21-2005, 05:07 PM
Here I redid your code, it should work now:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Why are you looking here? The blog's down there.</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>

<div align="center">
<div id="container">
<div id="image"><img src="winterdrop.jpg" alt="Header image" /></div>
<div class="main">
<?php
//connect to the database
require_once("config.php");

//gather the posts
$gather_posts_res = mysql_query("SELECT entry, title, date_format(create_time, '%b %e %Y at %r') AS fmt_create_time FROM entries ORDER BY create_time DESC",$db) or die(mysql_error());

//what to do if there are posts or not
if (mysql_num_rows($gather_posts_res) < 1) {//there are no posts
$display_block="Antibaseball has not posted";
}
else {
//create the display string
while ($blog_info=mysql_fetch_array($gather_posts_res)) {
$entry_text=$blog_info['entry'];
$entry_title=$blog_info['title'];
$entry_create_tme=$blog_info['create_time'];
$display_block="<div class=\"post\"><span class=\"header\">$entry_title</span><p></p><span class=\"timestamp\">$entry_create_time</span><p></p>$entry_text</div><p></p><p></p>";
}
}
?>
<p>
<?php
echo $display_block;
?>
</div>
<div class="nav">Nav stuff</div>
</div>
</div>

</body>

</html>


You forgot a } at the end there ;)

onigiri
12-21-2005, 10:41 PM
AAAARRRRGGGGHHHH, how could I miss that? *Looks for place to bang head against*

Thanks Douglas, you're a lifesaver!

Douglas
12-22-2005, 12:52 AM
No problem, I didn't see it at first either :lol: