Page 1 of 1

Undefined var problem.

Posted: Sat Oct 31, 2009 9:58 am
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

Re: Undefined var problem.

Posted: Sat Oct 31, 2009 10:20 am
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.