警告:mysqli_free_result()期望参数1为mysqli_result

时间:2015-06-08 03:32:15

标签: php android database mysqli

我在mysqli_free_result中收到警告,但我自己无法解决。我有一个Android应用程序通过Web服务连接数据库。当我在localhost中测试它时工作正常,但当我尝试在我的webhost(hostgator)中运行时,我收到此警告。我发现与此警告相关的所有内容都是因为查询不是Insert或Select类型,但我的是。请看一下代码。

警告:mysqli_free_result()要求参数1为mysqli_result,第54行的/home/loupp759/public_html/AppBackEnd/dbmanager.php中给出布尔值{“result”:“false”,“message”:“您已取消注册。请尝试输入正确的信息“}

 function login($username){
       $con = connectDB();
       $query = "select id, nome, username, grupo from Participantes where username = '$username';";
        $res = mysqli_query($con, $query);
        $response = array();
        $response['result'] = 'false';
        $response['message'] = 'You are Unregisterd.'
                . 'Try to input correct Information';
        if( $res == FALSE ){

        }else{
            $num = mysqli_num_rows($res);
            if($num > 0 ){
                $row = mysqli_fetch_row($res);
                $response['result'] = 'true';

                $data = array();
                $data['id'] = $row[0];
                $data['name'] = $row[1];
                $data['username'] = $row[2];
                $data['group'] = $row[3];
                $response['message'] = $data;
            }
        }
        mysqli_free_result($res); <-------- this is the line of the error
        mysqli_close($con);
        return json_encode($response);
   }

谢谢大家

1 个答案:

答案 0 :(得分:-1)

  

首先更正您的查询

$query = "select id, name, username, group from Participantes where username = '$username'";
     

并将字段名称与您的回复相匹配