What are some best practices for updating a webpage in PHP after saving settings to a MySQL database?

When updating a webpage in PHP after saving settings to a MySQL database, it is important to ensure that the webpage reflects the changes made in the database. One way to achieve this is by fetching the updated settings from the database and using them to dynamically update the content of the webpage. This can be done by querying the database for the latest settings and then using PHP to populate the webpage with the updated information.

<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Query the database for the updated settings
$sql = "SELECT setting1, setting2 FROM settings_table";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "Setting 1: " . $row["setting1"]. "<br>";
        echo "Setting 2: " . $row["setting2"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>