prepare('SELECT 1 FROM recipes WHERE rowid = ?'); $checkValidRecipe->execute([$_GET["id"]]); if (count($checkValidRecipe->fetchAll()) > 0) { $checkAlreadyFavorite = $db->prepare('SELECT 1 FROM ' . $_GET["attr"] . ' WHERE recipe_id = ?'); $checkAlreadyFavorite->execute([$_GET["id"]]); if (count($checkAlreadyFavorite->fetchAll()) == 0 && !isset($_GET["remove"])) { $sth = $db->prepare('INSERT INTO ' . $_GET["attr"] . '(recipe_id) VALUES (?)'); if ($sth->execute([$_GET["id"]]) === 0) { http_response_code(500); die(); } http_response_code(201); die(); } else if (isset($_GET["remove"])) { $sth = $db->prepare('DELETE FROM ' . $_GET["attr"] . ' WHERE recipe_id = ?'); if ($sth->execute([$_GET["id"]]) === 0) { http_response_code(500); die(); } http_response_code(200); die(); } http_response_code(200); die(); } http_response_code(404); die(); } http_response_code(400); die(); } catch (Exception $e) { http_response_code(500); die(); }