As a newbie in PHP, I tried to make my own site and faced 2 errors, here's the code:
<?php
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "db name";
$conn = new mysqli($servername, $username, $password, $dbname);
$num = $_GET['id'];
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = "SELECT date, point, reason, teacher, giver FROM penalty WHERE studentid=$num";
$result = $conn->query($sql);
if ($result->num_rows > 0) 
{   
    echo "<table>";
    echo "<tr>";
    echo "<td>date</td>";
    echo "<td>score</td>";
    echo "<td>reason</td>";
    echo "<td>giver</td>";
    echo "<td>teacher</td>";
    echo "</tr>";
    while($row = $result->fetch_assoc()) 
    {
        echo "<tr>";
        echo "<td>".$row["dated"]."</td>";
        echo "<td>".$row["point"]."</td>";
        echo "<td>".$row["reason"]."</td>";
        echo "<td>".$row["giver"]."</td>";
        echo "<td>".$row["teacher"]."</td>";
        echo "</tr>";
    }
    echo "</table>";
}
else if ($result->num_rows = 0)
{
    echo "0!";
}
else 
{
    echo "empty";
}
$conn->close();
?>
and the results:
Notice: Trying to get property of non-object in view.php on line 16 Warning: Creating default object from empty value in view.php on line 39 empty
What can be the problem to cause this error, and how should I fix it?
Thanks in advance
