How can conditional statements be used to control form actions in PHP?
Conditional statements in PHP can be used to control form actions by checking the values submitted in the form fields. For example, you can use an if statement to check if a specific form field has a certain value, and then perform different actions based on that condition. This can be useful for validating form data, redirecting users to different pages, or processing form submissions differently based on certain criteria.
if ($_POST['submit']) {
$username = $_POST['username'];
if ($username == 'admin') {
// Perform action for admin user
echo 'Welcome admin!';
} else {
// Perform action for regular user
echo 'Welcome ' . $username . '!';
}
}