PS: Also, you have a </tr>
tag in the data row where you want a <td>
tag. It might help to break up the lines and do some indenting so that some of those things are easier to see, something like:
if ($result->num_rows > 0) {
echo "
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Course</th>
<th>Grade Code</th>
<th>Grade Percentage</th>
</tr>";
while ($row = $result->fetch_assoc()) {
echo "
<tr>
<td>" . $row["studentfname"] . "</td>
<td>" . $row["studentlname"] . "</td>
<td>" . $row["course"] . "</td>
<td>" . $row["gradecode"] . "</td>
<td>" . $row["gradep"] . "</td>
</tr>";
}
}