UPDATE: I've edited the question to be more specific:
so the problem was a hidden character i could only see openning the file on my webhost editor, and then it was missing '' on the $id
So, i've already looked everywhere for an answer, and i simply can't find it, so was wondering if someone can point me in the right direction.
I am following this tutorial: https://www.simplifiedcoding.net/android-mysql-tutorial-to-perform-basic-crud-operation/ to learn how to make CRUD operations connecting my app with MySQL server, and i got stuck on the part to get a single entry from table.
It gives me a "Parse error: syntax error, unexpected 'echo' (T_ECHO) in /home/u728774671/public_html/db/getpost.php on line 28" and i can't figure out why, my code is exactly as the one in the tutorial, except i changed name of table and variables.
what am i missing? am i doing something wrong or is it the tutorial code?
here is the code:
<?php
//Getting the requested id
$id = $_GET['id'];
//Importing database
require_once('dbconnect.php');
//Creating sql query with where clause to get an specific employee
$sql = "SELECT * FROM posts WHERE id='$id'";
//getting result
$r = mysqli_query($con,$sql);
//pushing result to an array
$result = array();
$row = mysqli_fetch_array($r);
array_push($result,array(
"id"=>$row['id'],
"titulo"=>$row['titulo'],
"usuario"=>$row['usuario'],
"endereco"=>$row['endereco'],
"post"=>$row['post'],
"imagem"=>$row['imagem']
));
//displaying in json format
echo json_encode(array('result'=>$result));
mysqli_close($con);
?>
this is the line where the error is:
echo json_encode(array('result'=>$result));
and this is the code from the tutorial:
<?php
//Getting the requested id
$id = $_GET['id'];
//Importing database
require_once('dbConnect.php');
//Creating sql query with where clause to get an specific employee
$sql = "SELECT * FROM employee WHERE id=$id";
//getting result
$r = mysqli_query($con,$sql);
//pushing result to an array
$result = array();
$row = mysqli_fetch_array($r);
array_push($result,array(
"id"=>$row['id'],
"name"=>$row['name'],
"desg"=>$row['designation'],
"salary"=>$row['salary']
));
//displaying in json format
echo json_encode(array('result'=>$result));
mysqli_close($con);
?>