How can PHP be used to display a confirmation message on the same page as a form submission?

When a form is submitted in PHP, we can use a conditional statement to check if the form has been submitted. If it has, we can display a confirmation message on the same page using PHP echo statement. This can be achieved by setting a variable to hold the message and then displaying it within the HTML code.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Form has been submitted
    $message = "Form submitted successfully!";
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Form Submission Confirmation</title>
</head>
<body>
    <?php if(isset($message)) { ?>
        <p><?php echo $message; ?></p>
    <?php } ?>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <!-- Your form fields here -->
        <input type="submit" value="Submit">
    </form>
</body>
</html>