PHP错误:试图在空行

时间:2017-01-14 00:30:22

标签: php mysql mysql-error-1064

我已经查看了一些类似问题的答案,但却未能适用于我的问题。

我收到了错误:

Notice: Trying to get property of non-object in /storage/h2/548/534548/public_html/index.php on line 22
0 results

...来自以下代码,我从w3schools网站大量借用了这些代码:

<html>
 <head>
  <title>Nationometer</title>
 </head>
 <body>
<?php
$servername = "localhost";
$username = "xxxxxxxxxxxx";
$password = "xxxxxxxxxxxx";
$dbname = "jonnationometer";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT ID, Site_Name, Weather_Forecast, Forecast_Date, Forecast_Time, Further_Information_about_This_Site FROM SiteList";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<br>" .$row["ID"]. $row["Site_Name"]. $row["Weather_Forecast"]. $row["Forecast_Date"]. $row["Forecast_Time"]. $row["Further_Information_about_This_Site"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>
 </body>
</html>

错误语句突出显示的第22行是空白的(或者在脚本中计算时是否忽略空行?)

非常感谢任何人都可以就如何调整脚本以使其返回数据提供一些指导。

0 个答案:

没有答案