What is the best practice for checking if a forum with a specific ID exists in PHP?

To check if a forum with a specific ID exists in PHP, you can query the database to see if a record with that ID exists in the forums table. If a record is found, then the forum exists, otherwise it does not.

<?php
$forum_id = 123; // Specify the forum ID you want to check

// Connect to the database
$conn = new mysqli("localhost", "username", "password", "database");

// Check if the forum with the specified ID exists
$result = $conn->query("SELECT * FROM forums WHERE id = $forum_id");

if ($result->num_rows > 0) {
    echo "Forum with ID $forum_id exists.";
} else {
    echo "Forum with ID $forum_id does not exist.";
}

// Close the database connection
$conn->close();
?>