Why is my variable undefined?
<p>I have noticed this is a common error in <code>php</code> and i tried to search the net and i can not get my answer, I am trying to create a simpe forum and I am getting these errors</p>

<pre><code>Notice: Undefined variable: topics in C:\xampp\htdocs\mysite\Students forum\view_category.php on line 83

Notice: Undefined variable: topic in C:\xampp\htdocs\mysite\Students forum\view_category.php on line 86
</code></pre>

<p>and this is the code on line 83</p>

<pre><code>$topics .= "&lt;table width='100%' style='border-collapse: collapse;'&gt;";
</code></pre>

<p>and this is the code on line 86</p>

<pre><code>$topic .= "&lt;tr&gt;&lt;td colspan='4'&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;";
</code></pre>

<p>and this is my code </p>

<pre><code>if (mysql_num_rows($res2) &gt; 0) {
        // Appending table data to the $topics variable for output on the page
        $topics .= "&lt;table width='100%' style='border-collapse: collapse;'&gt;";
        $topics .= "&lt;tr&gt;&lt;td colspan='4'&gt;&lt;a href='index.php'&gt;Return To Forum Index&lt;/a&gt;".$logged."&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;";
        $topics .= "&lt;tr style='background-color: #dddddd;'&gt;&lt;td&gt;Topic Title&lt;/td&gt;&lt;td width='65' align='center'&gt;Last User&lt;/td&gt;&lt;td width='65' align='center'&gt;Replies&lt;/td&gt;&lt;td width='65' align='center'&gt;Views&lt;/td&gt;&lt;/tr&gt;";
        $topic .= "&lt;tr&gt;&lt;td colspan='4'&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;";
        // Fetching topic data from the database
        while ($row = mysql_fetch_assoc($res2)) {
            // Assign local variables from the database data
            $tid = $row['id'];
            $title = $row['topic_title'];
            $views = $row['topic_views'];
            $date = $row['topic_date'];
            $creator = $row['topic_creator'];
            // Check to see if the topic has every been replied to
            if ($row['topic_last_user'] == "") { $last_user = "N/A"; } else { $last_user = getusername($row['topic_last_user']); }
            // Append the actual topic data to the $topics variable
            $topics .= "&lt;tr&gt;&lt;td&gt;&lt;a href='view_topic.php?cid=".$cid."&amp;tid=".$tid."'&gt;".$title."&lt;/a&gt;&lt;br /&gt;&lt;span class='post_info'&gt;Posted by: ".getusername($creator)." on ".convertdate($date)."&lt;/span&gt;&lt;/td&gt;&lt;td align='center'&gt;".$last_user."&lt;/td&gt;&lt;td align='center'&gt;".topic_replies($cid, $tid)."&lt;/td&gt;&lt;td align='center'&gt;".$views."&lt;/td&gt;&lt;/tr&gt;";
            $topics .= "&lt;tr&gt;&lt;td colspan='4'&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;";
        }
        $topics .= "&lt;/table&gt;";
        // Displaying the $topics variable on the page
        echo $topics;
    } 
</code></pre>
