Undefined var problem.

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
nits4u
Forum Newbie
Posts: 15
Joined: Tue Jun 23, 2009 3:44 am

Undefined var problem.

Post by nits4u »

i m using "<<<" method for the 1st time.
it shows the following Notices:
Notice: Undefined variable: details in C:\wamp\www\php\table.php on line 32

Notice: Undefined variable: fotr in C:\wamp\www\php\table.php on line 45

here is the code....

<?php
//adding data in table
include "var1.php";
mysql_select_db('wiley') or
die("can't connect".mysql_error());
$query="SELECT movie_name,
movie_leadactor,
movie_director
FROM movie";
$result=mysql_query($query)or
die (mysql_error());
$num=mysql_fetch_row($result);
$movie_hdr=<<<h
<h2><center>Movie Reviews</center></h2>
<table width='80%' cellpadding='2' cellspacing='2'>
<tr>
<td>Movie</td>
<td>Actor</td>
<td>Director</td></tr>
h;
while($row=mysql_fetch_array($result)){
$moviename=$row['movie_name'];
$movieactor=$row['movie_leadactor'];
$moviedirector=$row['movie_director'];

$details.=<<<dtl
<tr>
<td>$moviename</td>
<td>$movieactor</td>
<td>$moviedirector</td>
</tr>
dtl;
}
$details.=<<<dtl
<tr>
<td>&nbsp;</td>
</tr>
<tr><td>Total: $num Movies</td></tr>
dtl;
$footer="</table>";
$fotr.=<<<ftr
$movie_hdr
$details
$footer
ftr;
print"there are $num movies.";
?>

Thank you
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Undefined var problem.

Post by cpetercarter »

I think the problem is your use of .=. You can use .= to add characters to an existing string. But you do not have existing strings $details or $fotr. So, either use = when you first create the string; or initialise the variables properly at the beginning of the script.
Post Reply