How can the problem of inserting duplicate data into the database be prevented after a page refresh in PHP?

Issue: The problem of inserting duplicate data into the database after a page refresh in PHP can be prevented by using a technique called POST/Redirect/GET (PRG). This involves redirecting the user to a different page after a form submission, which prevents the form from being resubmitted if the user refreshes the page.

// Check if the form has been submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process the form data and insert into the database
    
    // Redirect to a different page to prevent form resubmission
    header("Location: success.php");
    exit;
}