请求未发送到服务器

时间:2019-07-27 12:26:49

标签: php post flutter httprequest

我正在尝试建立一个登录页面,在其中检索用户名和密码值并将它们存储在两个变量中,这些变量发送到我的php文件中,在其中查找值是否存在,然后在onPressed按钮中进行搜索我处理两种情况。我同时使用了post方法和Dio(),但是由于我的数据没有发送,它们都不起作用。这是两种方法:

与Dio()

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

带帖子

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

(用户名和密码是存储用户输入内容的变量)

这是搜索值是否存在的php文件

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

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

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

   $stamement->execute();
 ?>

这是onPressed方法

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

1 个答案:

答案 0 :(得分:0)

我在您的代码中发现了一些错字:

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

如果您要创建登录/注册系统,我谨向您推荐这篇文章(但将加密算法更改为MD5以外的其他名称):
http://codewithawa.com/posts/complete-user-registration-system-using-php-and-mysql-database