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"):}
},