0

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

3
  • 1
    Warning! You are wide open for SQL injection attacks! You should use prepared statements with placeholders. Currently, you're using prepare() wrong. You're still injecting completely unescaped user data into the query directly instead of using placeholders, which makes the prepare() pointless and your query unsafe.. Commented Dec 2, 2020 at 8:46
  • @MagnusEriksson can you help me with that issue? Commented Dec 2, 2020 at 19:17
  • You need to expand on "wont work". What actually happens? What debugging have you done? Have you checked the browsers console for errors? Have you checked the network tab in the browser while making the request to see what data is sends and what the response is? Commented Dec 3, 2020 at 6:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.