I have a server.php file which is supposed to return a table of ints. Each one of these ints is linked to a key (some ints can have the same key). The table needs to only contain ints linked to a specific key.
To get one of these key, i need to have another key as a parameter.
So the process is :
The server is called by an $http.post (i'm using AngularJS) :
$http.post('server.php', {"data" : parameterKey, "serverFlag" : 4})
(serverFlag is not yet used, and parameterKey is a string)
I then use parameterKey to get anotherKey :
$data = file_get_contents("php://input");
$objData = json_decode($data);
$conn = new PDO(/*something*/);
$outp = [];
$anotherKey = $conn->query("SELECT anotherKey FROM myTable1 WHERE parameterKey = $objData->data");
$anotherKey = $anotherKey ->fetch();
Then, i use anotherKey to gather all the ints linked to this key :
$result = $conn->query("SELECT myInt FROM myTable2 WHERE id = $anotherKey ORDER BY myInt ASC");
while($rs = $result->fetch()) {
if ($outp != "") {
array_push($outp,$rs["myInt"]);
}
}
$outp =json_encode($outp);
echo($outp);
(I don't know if I have made myself very clear so far...)
So i have a JSON error when running this :
Error: JSON.parse: unexpected character at line 1 column 1 of the JSON data
I'm not really sure where the error is. Any ideas ?
EDIT
I have the following error :
Fatal error: Call to a member function fetch() on boolean in C:\wamp64 \www\tests\server.php on line <i>47</i>
(line 47 = $anotherKey = $anotherKey ->fetch();)