prepare( 'SELECT item.id FROM item INNER JOIN feed ON feed.id = item.feed_id WHERE item.id = :id AND feed.user_id = :user'); $existsQuery->bindValue(':id', $id); $existsQuery->bindValue(':user', $_SESSION[Key::USER_ID]); $existsResult = $existsQuery->execute(); $exists = $existsResult ? $existsResult->fetchArray(SQLITE3_ASSOC) : false; if (!$exists) not_found(); if (key_exists('action', $_GET)) { if ($_GET['action'] == 'add') { $flag = 1; } elseif ($_GET['action'] == 'remove') { $flag = 0; } if (isset($flag)) { $update = $db->prepare('UPDATE item SET is_bookmarked = :flag WHERE id = :id'); $update->bindValue(':id', $id); $update->bindValue(':flag', $flag); if (!$update->execute()) die(Data::error($db)['error']); } } $bookQuery = $db->prepare('SELECT id, is_bookmarked FROM item WHERE id = :id'); $bookQuery->bindValue(':id', $id); $bookResult = $bookQuery->execute(); $bookmark = $bookResult ? $bookResult->fetchArray(SQLITE3_ASSOC) : ['id' => $id, 'is_bookmarked' => 0]; $action = $bookmark['is_bookmarked'] ? 'remove' : 'add'; $icon = $bookmark['is_bookmarked'] ? 'added' : 'add'; ?>