【问题标题】:Notice: Trying to get property of non-object in C:\xampp\htdocs\getallemlpoyees.php on line 28 0 results注意:尝试在 C:\xampp\htdocs\getallemlpoyees.php 中获取非对象的属性在第 28 行 0 结果
【发布时间】:2019-07-15 16:51:21
【问题描述】:

我的 PHP 脚本有语法错误:

注意:试图获取非对象的属性 C:\xampp\htdocs\getallemlpoyees.php 第 28 行 0 结果

    $sql = "SELECT id, firstname, lastname, FROM employees";


    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {


        echo "<br> ID: ".$row["id"]. "- firstname: ".$row["firstname"] ." lastname: ". $row["lastname"] . "<br>";



    }
} 

    else {
        echo "0 results";
    }

【问题讨论】:

  • 您的查询失败,原因是姓氏后面多了一个逗号。在查询后检查mysqli errors 会指出这一点。
  • 查看重复链接以了解如何启用 mysqli 错误报告。

标签: php sql database


【解决方案1】:

$sql = "SELECT id, firstname, lastname, FROM employees";

lastname 后面不要加逗号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 2017-08-24
    相关资源
    最近更新 更多