I am working in flutter app that connect to the phpMyAdmin. I have to check the phone number if it’s found in the database or not found and it’s works and the result "found" or not return into the debug console successfully. My problem is how can i connect the flutter to the result from php? if it’s found i want to print a message and if it not show another message.
this is the php :
<?php
include "config.php"; // call connection
$err= array();
$phone_login = $_POST["login_phone"];
try{
$stmt = $connect->prepare("SELECT * FROM profile WHERE phone = ?");
$stmt->execute(array($phone_login));
$count = $stmt->rowCount();
}catch(PDOException $e){
echo $e-> getMessage();}
if($count > 0){
echo json_encode(array("status" => "found"));
}else{
echo json_encode(array("status" => "not found"));
}
?>
and this is the function in login.dart:
const String linklogin = "$linkServerName/checkphone.php";
JsonAPI _tst = JsonAPI();
login() async {
var response = await _tst.postRequest(linklogin, {
"login_phone": mobileNumTF_login.text,
});
if (response['status'] == "found") {
print("found");
} else {
print("not found");
}
}
How can i do an action in flutter app if i received the found and not found?
2
Answers
You can use a FutureBuilder, pass the login() future and display a Text() widget as follows: