PHP Notice: Trying to get property of non-object in post.php on line 8
本问题已经有最佳答案,请猛点这里访问。
我收到此错误
PHP Notice: Trying to get property of non-object in post.php on line
8
在下面的代码上
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php if (is_numeric($_GET["id"])) { $mysqli=mysqli_connect("localhost","xxx","xxx","xxx"); $query = $mysqli->query("SELECT n FROM table WHERE o=".$_GET["id"]); if ($query) { if ($query->num_rows === 0) { header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.example.com/?p=".$query->fetch_object()->n); } } mysqli_close($mysqli); } else { echo $_GET["id"]; } |
知道发生了什么吗?我假设我进行的检查将确保仅通过有效数据
谢谢
1
|
SELECT n FROM `table` WHERE o=".$_GET["id"]
|
更新
为了获取数据,你必须使用 while 循环
1
2 3 |
检查 http://php.net/manual/en/mysqli-result.fetch-object.php
您正在尝试处理空结果。你问结果是否有 0 行,然后尝试获取一行结果必须是 0 行:
1
2 3 4 |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/268495.html