这一行出错误while($data = $result ->fetch_row())
用法没有错,可以检查一下你查询的表是否存在,一般存在这么写是没有问题的。
一楼说的对,我这里补充一下,有可能 result=null