Success Messages on Form Submission in PHP
Let's now make it so that after the redirect to the page, a message about the successful save is displayed. We will use flash messages for this:
<?php
session_start();
if (!empty($_POST)) {
// save to database
$_SESSION['flash'] = 'form successfully saved';
header('Location: form.php');
die();
}
if (isset($_SESSION['flash'])) {
echo $_SESSION['flash'];
unset($_SESSION['flash']);
}
?>
Modify the previous task so that a message about the successful form submission is displayed on the screen.