How can PHP sessions be used to store and retrieve data between form submissions?
PHP sessions can be used to store data between form submissions by storing the data in the $_SESSION superglobal array. This allows the data to persist across multiple page loads until the session is destroyed. To store data, you can assign values to $_SESSION variables, and to retrieve the data, you can access these variables in subsequent requests.
<?php
// Start the session
session_start();
// Store form data in session variables
$_SESSION['username'] = $_POST['username'];
$_SESSION['email'] = $_POST['email'];
// Retrieve stored data
$username = $_SESSION['username'];
$email = $_SESSION['email'];
// Display the stored data
echo "Username: " . $username . "<br>";
echo "Email: " . $email;
?>