What potential issue arises when a user refreshes a PHP form after submitting data to a MySQL database?

When a user refreshes a PHP form after submitting data to a MySQL database, it can result in duplicate entries being inserted into the database. This occurs because refreshing the page resubmits the form data, causing the same data to be sent to the database again. To prevent this issue, you can use the Post/Redirect/Get (PRG) pattern. This involves processing the form submission, redirecting to a different page after successfully inserting data into the database, and then using a GET request to display the new page.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form submission and insert data into MySQL database

    // Redirect to a different page to prevent form resubmission
    header("Location: success.php");
    exit();
}
?>