Page 1 of 1

[Solved] Help with Parse Error, unexpected T_VARIABLE

Posted: Mon Mar 22, 2004 10:40 am
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?

Posted: Mon Mar 22, 2004 10:43 am
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>; 
} ";
??

Posted: Mon Mar 22, 2004 10:50 am
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).

Posted: Mon Mar 22, 2004 10:54 am
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

Posted: Mon Mar 22, 2004 10:54 am
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>";
?>

Posted: Mon Mar 22, 2004 11:02 am
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>";
}

?>

Posted: Mon Mar 22, 2004 2:14 pm
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.

Posted: Mon Mar 22, 2004 3:04 pm
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*

Posted: Tue Mar 23, 2004 7:52 am
by malcolmboston
indeed -hugs zend :lol:

Posted: Tue Mar 23, 2004 5:15 pm
by tim
- hugs full 12 pack of cold beer

8) 8)

Posted: Tue Mar 23, 2004 7:30 pm
by d3ad1ysp0rk
*hugs..

..

...

*looks around for something to hug*
..

..
....

*hugs door*