A few years ago I created a backend (PHP to get some json data) for some mobile apps of mine. I haven't touched this code since then. Now it stopped working weeks ago. I'm not a backend developer so I don't have much experience here, but a few years ago I thought it would be better to create my own backend instead of using Firebase/Serverless... which wasn't my best idea: )
What I tried:
One moment, please... Please wait while your request is being verified...
This is my php file:
$response = array(); function saveResultOfQueryToArray($result){ global $response; $response['workouts'] = array(); while($row = mysqli_fetch_array($result)){ $temp = array(); // $temp['aufruf'] = $aufruf; $temp['error'] = false; $temp['workoutname'] = $row['workoutname']; $temp['duration'] = $row['duration']; ... array_push($response['workouts'],$temp); } } if($_SERVER['REQUEST_METHOD']=='GET') { $db = new DbOperation(); $users = $db->getHighestRatingWith31Results(); saveResultOfQueryToArray($users, $chooseMethod); } else { $response['error'] = true; $response['message'] = "Invalid Request"; } echo json_encode($response);
Can someone explain to me what I'm doing wrong/what can be changed?
Looks
if($_SERVER['REQUEST_METHOD'] == 'GET')
There is no$response
. Unless there is more in the code,$response
is undefined.Something like this should do the trick! I also recommend looking at the HTTP response, such as HTTP 405.https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
Edit: I saw your update and I'm sorry, but it raises more questions. In other words, what does
$db->getHighestRatingWith31Results();
do? FunctionsaveResultOfQueryToArray()
accepts one parameter, but the usage is to provide two parameters to the function? saveResultOfQueryToArray is calling mysqli_fetch_array(), which requires a mysqli_result instance.This is my suggestion:
saveResultOfQueryToArray()
or consider passing it by reference.https://www.php.net/manual/en/language. references.pass.php