作为PHP的新手,我尝试创建自己的网站并面临2个错误,这里是代码:
<?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();
?>
和结果:
注意:尝试在第16行的view.php中获取非对象的属性 警告:在view.php中从空值创建默认对象 39空
导致此错误的问题是什么,我应该如何解决?
提前致谢