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

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.