首页 > 解决方案 > 在flutter中使用php mysql根据用户登录显示数据

问题描述

我想显示表用户的用户配置文件数据。这是我的 PHP 代码:

<?php

   include ("connect.php");

   //$username = $_POST['username'];

   $response = array();

   $sql = mysqli_query($con,"SELECT agentName, agentCode, agentId FROM users WHERE username ='$username'");

   while ($a = mysqli_fetch_array($sql)){


       $b['agentName'] = $a['agentName'];
       $b['agentCode'] = $a['agentCode'];
       $b['agentId'] = $a['agentId'];

       array_push($response, $b);

   }
   echo json_encode($response);
?>

但它不显示,但是当我用特定的用户名更改用户名时,数据会显示。我的代码有问题吗?

这是上面编码的结果

数据将显示在

_lihatUser() async {
    list.clear();
    setState(() {
        loading=true;
    });

    final response = await http.get(BaseUrl.userData);
    if (response.contentLength==2){
    }else{
        final data = jsonDecode(response.body);
        data.forEach((api){
            final ab = new userModel(
                api['agentCode'],
                api['agentId'],
                api['agentName']
            );
            list.add(ab);
        });
        setState(() {
            loading=false;
        });
    }
}

标签: phpmysqlflutter

解决方案


推荐阅读