require 'config.php';
$query="SELECT * FROM topics WHERE student_id='".$_SESSION['id']."' AND id='".$_GET['id']."';";
$result=mysql_query($query) or die(mysql_error());
<td colspan="2"><?php echo $_SESSION['user_name']; ?></td>
<td colspan="8"><b><?php echo $rows['title']; ?></b></td>
<td colspan="2"></td>
<td colspan="8"><?php echo $rows['description']; ?></td>
<?php $sql="SELECT * FROM comments WHERE topic_id='".$_GET['id']."';"; 
$comment_result=mysql_query($query) or die(mysql_error());
  <td colspan="2">
      <?php $t_query="SELECT * FROM users WHERE id='".$row['teacher_id']."';";
             $result=mysql_query($t_query) or die(mysql_error());
             echo $trow['user_name'];
  <td colspan="8"><?php echo $row['comment']; ?></td>

I am having this code.
It is giving error
Notice:Undefined index: teacher_id in /opt/lampp/htdocs/register/viewtopic.php on line 24

Notice: Undefined index: comment in /opt/lampp/htdocs/register/viewtopic.php on line 30

Seems like $row['teacher_id'] and $row['comment'] haven't got a value. Insert the following after the line 19:

if(!isset($row['teacher_id']) or empty($row['teacher_id']) or !isset($row['comment']) or empty($row['comment'])) {
    die('<pre>' . print_r($row, 1) . '</pre>');

and post the output.

(the code above will check if any of the suspicious values do not exist and will display the array with values of $row variable at that time in preformated html).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.