douqie6454 2017-04-20 23:04
浏览 38
已采纳

MYSQLI语句错误显示不正确但正确

I am getting following error from PHP and MYSQL, but the SQL statement is correct, I grabbed it direct from PHPmyadmin, I have included a picture from PHPMYADMIN showing the table.

$sql = 'SELECT * FROM company';

if ($mysqli->query($sql) === TRUE) {
    $result = $mysqli->query($sql);
    if ($result->num_rows > 0) {
    (data from result's)
    }
} else {
   echo "Error: " . $sql . "<br>" . $mysqli->error;
   exit();
}

Result: (There is nothing from $mysqli->error;)

Error: SELECT * FROM company

Inserted 2 rows into the table, still getting same error.

2 rows

Removed the first if statement.

Now getting following error:

( ! ) Notice: Trying to get property of non-object in C:\xampp\htdocs\mkpenterprices\Research.php on line 248

Finally got the SQL to run but its not populating anything on the javascript section.

  • 写回答

1条回答 默认 最新

  • dongtang1997 2017-04-20 23:20
    关注

    Simply do this

    $sql = 'SELECT * FROM company';
    
    
    $result = $mysqli->query($sql);
    
    if(!$result){
        echo "Error: " . $sql . "<br>" . $mysqli->error;
       exit();
    
    }
    
    if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
            var_dump($row);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?