I already tried this: A previous question
But it wont work! Nothing appears in the App! This is my flutter code to set Data .. num is equal to 1 so I can get the first user:
Future setData() async {
final response = await http.post(theUrl, body: {"id": num});
setResponse = json.decode(response.body);
return setResponse;
}
and this is for getting theData Flutter Code:
Future getMethod() async {
String theUrl = "http://192.168.8.53/flutter_test/phpConnect.php";
var res = await http
.get(Uri.encodeFull(theUrl), headers: {"Accept": "application/json"});
responseBody = json.decode(res.body);
return responseBody;
}
this is my php getData.php code:
<?php
require('connection.php');
$userId = $_POST['id'];
$makeQuery = "Select * From tableName Where id=" .$userId;
$statement = $connection->prepare($makeQuery);
$statement->execute();
$myarray = array();
while ($resulteFrom = $statement ->fetch()){
array_push(
$myarray,array(
"id"=>$resultFrom['id'],
"header"=>$resultFrom['header'],
"body"=>$resultFrom['body']
)
);
}
echo json_encode($myarray);
?>
Thanx in Advance <3
prepare()wrong. You're still injecting completely unescaped user data into the query directly instead of using placeholders, which makes theprepare()pointless and your query unsafe..