问题:试图获得非对象的属性 [英] Problem: trying to get property of non-object
问题描述
我在html中的表单中的输入类型是datetime-local并保存在mysql的表中。
在我的mysql表中,我创建了一个名为deadline的列,其类型为datetime。 />
我尝试显示截止日期之后的行。
但是,它显示错误试图获取非对象的属性。
我不明白为什么。
我尝试了什么:
<?php
$ servername =localhost;
$ username =root;
$ password =;
$ dbname =MyDB;
//创建连接
$ conn = new mysqli($ servername,$ username,$ password,$ dbname);
//检查连接
$ sql =SELECT Ass,Deadline,FROM Board WHERE Deadline> = NOW();
$ result = $ conn->查询($ sql);
if($ result-> num_rows> 0) {
//每行输出数据
while($ row = $ result-> fetch_assoc()){
echo< br>作业:。 $行[驴。 - 最后期限: 。 $行[截止日期。
;
}
}其他{
echo0 results;
}
$ conn-> close();
?>
My input type in a form in html is datetime-local and keep in a table in mysql.
In my table in mysql, i created a column named deadline whose type is datetime.
I try to display a row which deadline is after now.
But, it shows the error "Trying to get property of non-object".
I don't understand why.
What I have tried:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "MyDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
$sql = "SELECT Ass, Deadline, FROM Board WHERE Deadline >= NOW()";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "
Assignment: ". $row["Ass"]. " - Deadline: ". $row["Deadline"]. "
";
}
} else {
echo "0 results";
}
$conn->close();
?>
推荐答案
servername =localhost;
servername = "localhost";
username =root;
username = "root";
password =;
password = "";
这篇关于问题:试图获得非对象的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!