[Solved] Help with Parse Error, unexpected T_VARIABLE

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
User avatar
bironeb
Forum Commoner
Posts: 59
Joined: Thu Nov 20, 2003 12:02 pm

[Solved] Help with Parse Error, unexpected T_VARIABLE

Post by bironeb »

Here is my code:

Code: Select all

<?php
$db_name = "testDB";
$table_name = "my_music";
$connection = @mysql_connect("localhost", "byron", "byronb") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT id, format, title, artist_fn, artist_ln, rec_label, 
my_notes, date_acq FROM $table_name ORDER BY id";
$result = @mysql_query($sql, $connection) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
	$id = $row['id'];
	$format = $row['format'];
	$title = stripslashes($row['title']);
	$artist_fn = stripslashes($row['artist_fn']);
	$artist_ln = stripslashes($row['artist_ln']);
	$rec_label = stripslashes($row['rec_label']);
	$my_notes = stripslashes($row['my_notes']);
	$date_acq = $row['date_acq'];
	if ($artist_fn != "") {
		$artist_fullname = trim("$artist_fn $artist_ln");
		} else {
		$artist_fullname = trim("$artist_ln");
	}
	if ($date_acq == "0000-00-00") {
		$date_acq = "[unknown]";
	}
	$display_block .= "
	<P><strong>$title</strong> ($artist_fullname) <br>
	$my_notes <em> (acquired: $date_acq, format: $format)</em></p>;
}
?>
<html>
<head>
<title>My Music (Ordered by ID)</title>
</head>
<body>
<h1>My Music: Ordered by ID</h1>
<? echo "$display_block"; ?>
<p><a href="my_menu.html">Return to Menu</a></p>
</body>
</html>
Im getting the below error:


Parse error: parse error, unexpected T_VARIABLE on line 37

Line 37 is the line below:

Code: Select all

<? echo "$display_block"; ?>
Any Ideas?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

you wrote: $display_block .= "
<P><strong>$title</strong> ($artist_fullname) <br>
$my_notes <em> (acquired: $date_acq, format: $format)</em></p>;
}
should be

Code: Select all

$display_block = " 
   <P><strong>$title</strong> ($artist_fullname) <br> 
   $my_notes <em> (acquired: $date_acq, format: $format)</em></p>; 
} ";
??
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

T_VARIABLE normally means something wrong with variables not having $ on them. This does not seem to be the case here..

Looking athe code

Code: Select all

$display_block.= "
   <P><strong>$title</strong> ($artist_fullname) <br>
   $my_notes <em> (acquired: $date_acq, format: $format)</em></p>";
 // Append to existing
should be OK although I would set $display_block=""; before the while to prevent a possible PHP warning.

Try <?php echo("$display_block"); ?> in your last area...

(Note brackets).
Last edited by CoderGoblin on Mon Mar 22, 2004 10:57 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

your all wrong

should be like this (notice position of last quote and last curly brace)

Code: Select all

$display_block .= " 
   <P><strong>$title</strong> ($artist_fullname) <br> 
   $my_notes <em> (acquired: $date_acq, format: $format)</em></p>"; 
}
Mark
Last edited by JayBird on Mon Mar 22, 2004 10:55 am, edited 1 time in total.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

you've forgotten to end the string,

Code: Select all

<?php
$display_block .= "
   <P><strong>$title</strong> ($artist_fullname) <br>
   $my_notes <em> (acquired: $date_acq, format: $format)</em></p>;
?>
should be

Code: Select all

<?php
$display_block .= "
   <P><strong>$title</strong> ($artist_fullname) <br>
   $my_notes <em> (acquired: $date_acq, format: $format)</em></p>";
?>
User avatar
bironeb
Forum Commoner
Posts: 59
Joined: Thu Nov 20, 2003 12:02 pm

Post by bironeb »

Thanks for your help guys, to fix the error I first used this line before the while loop:

Code: Select all

$display_block = "";
Then added the missing " on the line:

Code: Select all

$display_block .= "
	<P><strong>$title</strong> ($artist_fullname) <br>
	$my_notes <em> (acquired: $date_acq, format: $format)</em></p>";
}

?>
User avatar
werlop
Forum Commoner
Posts: 68
Joined: Sat Mar 22, 2003 2:50 am
Location: /dev/null

Post by werlop »

This is where syntax highlighting helps. If your editor supported that, you probably would have noticed you hadn't ended the string, as the text would be a different colour.
Last edited by werlop on Mon Mar 22, 2004 5:06 pm, edited 1 time in total.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

werlop wrote:This is where syntax highlighting helps. If your editor supported that, you probably would have noticed you hadn't ended the sting, as the text would be a different colour.
Indeed. *hugs Dreamweaver*
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

indeed -hugs zend :lol:
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

- hugs full 12 pack of cold beer

8) 8)
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

*hugs..

..

...

*looks around for something to hug*
..

..
....

*hugs door*
Post Reply