Hey Everyone,
I writing on here because I am taking a course on PHP and learning it by using the textbook PHP 6 Fast & Easy Web Development by Julie Meloni and came across a problem on an assignment that I dont know how to fix. Any who, in the assignment I was working on I wrote a script that shows data I have in a table in my broswer (which btw works) BUT it always gives me the following message:
Notice: Undefined variable: display_block in 127.0.0.1\sel_byid.php on line 29.
I have checked my code over and and am sure I copied it right but still get the notice.
Here's the code:
<?php
$db_name = "testDB";
$table_name = "my_music";
$connection = @mysql_connect("localhost", "brenda", "mouse") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name ORDER BY title";
$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>$id. $title</strong>on $rec_label, by $artist_fullname<br>$my_notes<em>(acquired: $date_acq, format: $format)</em></P>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Music (Ordered by Title)</title>
</head>
<body>
<H1>My Music: Ordered by Title</H1>
<?php echo "$display_block"; ?>
<P><a href="my_menu.html">Return to Menu</a></P>
</body>
</html>
I've been trying to fix it for like a week now and the only thing I understand from the notice is that this line:
$display_block .= "<P><strong>$id. $title</strong>on $rec_label, by $artist_fullname<br>$my_notes<em>(acquired: $date_acq, format: $format)</em></P>";
is trying to concatentate to a variable which does not exist ($display_block) and I dont know how to fix it...
Can anyone help me?