doxp30826 2019-07-27 12:26 采纳率: 0%
浏览 162

请求未发送到服务器

I'm trying to build a log in page where I retrieve the user name and password values and store them in two variables that I send to my php file where I search wether the values exist or not and then in the onPressed button I handle both cases. I used both post method and Dio() but none of them work since my data is not sent. Here are both methods :

with Dio()

Future postData() async {
    Response response = await Dio().post(
        "http://192.168.0.117/testlocalhost/annonces/LogIn.php",
        data: {"User_name": userName, "password": password}
        );
}

with post

Future postData() async {
 var url = "http://192.168.0.117/testlocalhost/annonces/LogIn.php";
    http.post(
        url,
        body: {"userName": "$userName", "password": "$password"}
        );
 }

(userName and password are the varibales where I store the user's input)

here is the php file that searches wether the values exist or not

 <?php
   require('TestLocalHost.php');

   $makeQuery = "SELECT * FROM user WHERE User_name=userName  AND   
   password=password";

   $stamement = $connection->prepare($makeQuery);

   $stamement->execute();
 ?>

and here's the onPressed method

onPressed: () {
         userName = userNameController.text;
         password = passwordController.text;
             if (postData() == null) {print("ERROR!");}
             else{print("Done"):}
              },
  • 写回答

1条回答 默认 最新

  • dragon2025 2019-07-27 15:55
    关注

    I found a few typos in your code:

    require('TestLocalHost.php');
    $makeQuery = "SELECT * FROM user WHERE user_name='$userName' AND password='$password'";
    $stamement = $connection->prepare($makeQuery);
    $stamement->execute();
    

    If you are creating Login/Register system I higly recomend this article to you (but lated change encryption algorithm to something other than MD5):
    http://codewithawa.com/posts/complete-user-registration-system-using-php-and-mysql-database

    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元