I've been having this problem for two days, the following code when executing it returns me: No body returned for response. I need a precise explanation and its respective application. From already thank you very much.
//UPDATE CLIENT
try{
if ($_SERVER['REQUEST_METHOD'] === 'PUT')
{
$db = new db();
$dbConn = $db->connect();
$id = $_GET['id'];
$stmt = $dbConn->prepare("UPDATE client SET client_name = :client_name,
cellphone = :cellphone,
email = :email,
assigned_task = :assigned_task,
remaining_days = :remaining_days
WHERE id = :id");
$stmt->bindValue(':id', $id);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$dbConn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
header('200 OK');
$message = 'Updated User';
echo json_encode($message);;
exit();
}
}catch(PDOException $e){
$error = [
'error' => true,
'text' => $e->getMessage()
];
}
The problem is that if the base controller fails, you are creating an array with an error, but it is never being displayed, that is, there is no
echo
, if it goes well. To solve it, an out-of-scope variable is createdtry-catch
and no matter where it lands, there will always be an answer.I hope you can help yourself with this. I don't have a development environment but I don't think it's hard to debug for you.