prepare("SELECT slug FROM categories WHERE slug = ?"); if (!$statement) { $slugError = true; $errorMessage = "An unexpected error occurred while adding the category."; break; } else { $tempSlug2 = $tempSlug . ($tempSlugCount > 1 ? '-' . strval($tempSlugCount) : ''); $statement->bind_param('s', $tempSlug2); $statement->execute(); $slugExistsResult = $statement->get_result(); if (!$slugExistsResult) { $slugError = true; $errorMessage = "An unexpected error occurred while adding the category."; $statement->close(); break; } else { $slugExists = boolval($slugExistsResult->fetch_assoc()); $statement->close(); if (!$slugExists) { $slug = $tempSlug2; } else { $tempSlugCount++; } } } } if (!$slugError) { $statement = $connection->prepare('INSERT INTO categories (name, slug) VALUES (?, ?);'); if (!$statement) { $errorMessage = "An unexpected error occurred while adding the category."; } else { $statement->bind_param('ss', $_POST['categoryname'], $slug); if (!$statement->execute()) { $errorMessage = "An unexpected error occurred while adding the category."; } else { $categoryAdded = true; } $statement->close(); } } } } elseif ($_POST['action'] == "rename") { if (!isset($_POST['category'], $_POST['categoryname']) || !$_POST['category'] || !$_POST['categoryname']) { $errorMessage = "You need to specify the category you want to rename and the new category name."; } elseif (!filter_var($_POST['category'], FILTER_VALIDATE_INT)) { $errorMessage = "Invalid category."; } else { $categoryID = intval($_POST['category']); $statement = $connection->prepare("SELECT id FROM categories WHERE id = ?"); if (!$statement) { $errorMessage = "An unexpected error occurred while renaming the category."; } else { $statement->bind_param('i', $categoryID); $statement->execute(); $result = $statement->get_result(); if (!$result) { $errorMessage = "An unexpected error occurred while renaming the category."; $statement->close(); } else { $isCategoryPresent = boolval($result->fetch_assoc()); $statement->close(); if (!$isCategoryPresent) { $errorMessage = "The selected category doesn't exist."; } else { $statement = $connection->prepare('UPDATE categories SET name = ? WHERE id = ?;'); if (!$statement) { $errorMessage = "An unexpected error occurred while renaming the category."; } else { $statement->bind_param('si', $_POST['categoryname'], $categoryID); if (!$statement->execute()) { $errorMessage = "An unexpected error occurred while renaming the category."; } else { $categoryRenamed = true; } $statement->close(); } } } } } } elseif ($_POST['action'] == "remove") { if (!isset($_POST['category']) || !$_POST['category']) { $errorMessage = "You need to specify the category you want to remove."; } elseif (!filter_var($_POST['category'], FILTER_VALIDATE_INT)) { $errorMessage = "Invalid category."; } else { $categoryID = intval($_POST['category']); $statement = $connection->prepare("SELECT id FROM categories WHERE id = ?"); if (!$statement) { $errorMessage = "An unexpected error occurred while removing the category."; } else { $statement->bind_param('i', $categoryID); $statement->execute(); $result = $statement->get_result(); if (!$result) { $errorMessage = "An unexpected error occurred while removing the category."; $statement->close(); } else { $isCategoryPresent = boolval($result->fetch_assoc()); $statement->close(); if (!$isCategoryPresent) { $errorMessage = "The selected category doesn't exist."; } else { $statement = $connection->prepare('DELETE FROM categories WHERE id = ?;'); if (!$statement) { $errorMessage = "An unexpected error occurred while removing the category."; } else { $statement->bind_param('i', $categoryID); if (!$statement->execute()) { $errorMessage = "An unexpected error occurred while removing the category."; } else { $categoryRemoved = true; } $statement->close(); } } } } } } else { $errorMessage = "Unknown action specified."; } } $pageTitle = "Categories"; include '../includes/moderation_header.php'; ?>
Category has been renamed.
'; } elseif ($categoryRemoved) { echo 'Category has been removed.
'; } ?>This will cause mods in the category you want to remove to be of invalid category.
An unexpected error occurred while fetching categories.
"; } else { $categoriesPresent = false; while ($category = $result->fetch_assoc()) { $categoriesPresent = true; echo 'Mods: ' . htmlspecialchars(number_format($category['count'], 0)) . '
No categories.
'; } } ?>