Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748<?php$VALID_TABLES = ["favorites", "tested", "excluded"];try { if (!isset($_GET["id"]) || !is_numeric($_GET["id"])) { http_response_code(400); die(); } if (!isset($_GET["attr"]) || array_search($_GET["attr"], $VALID_TABLES) === false) { http_response_code(400); die(); } if (isset($_GET["username"]) && preg_match('/^[a-z]+$/i', $_GET["id"]) !== false) { $db = new PDO("sqlite:/var/www/html/user/db/" . $_GET["username"] . ".db"); $basedb = new PDO("sqlite:/var/www/html/_base.db"); $checkValidRecipe = $basedb->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();}