So I have a project of mine which we had been testing in a server using Google Cloud Platform. However, there is a bug where my API endpoint is not returning anything from an AJAX get request when a specific query string id is specified (does not happen in localhost). Here is the code, I am also aware about the sql injection risks so bear with me.
PHP Endpoint Script:
<?php
header("Content-Type: application/json");
include_once __DIR__.'/../helpers/mysql.php';
include_once __DIR__.'/../helpers/helper.php';
$helper = new Helper();
$db = new Mysql_Driver();
if (isset($_GET["module_id"]))
{
$module_id = $_GET["module_id"];
$db->connect();
$query = "SELECT m.*, i.item_path FROM Module m INNER JOIN Item i ON m.module_id = i.module_id WHERE m.module_id=$module_id";
$moduleInfoResult = $db->query($query);
// $moduleInfo = $db->fetch_array($moduleInfoResult);
if ($db->num_rows($moduleInfoResult) > 0) {
$moduleInfoResult = $db->fetch_array($moduleInfoResult);
$response = array(
'status' => 200,
'message' => 'Success',
'data' => $moduleInfoResult
);
} else {
$response = array(
'status' => 404,
'message' => 'Query Failed: Query return 0 records'
);
}
} else {
$response = array(
'status' => 400,
'message' => 'Error Occured: Must provide module_id query string'
);
}
echo json_encode($response)
?>
Screenshots of result using postman (id that is working):
Screenshots of result using postman (id that is not working but works in localhost):
What I have tried I tried echo'ing out the response and by using Postman I realized that ids that are returning nothing has this character:
Is there a way to prevent or escape this character?