How can PHP be used to process form data and execute commands based on user input?
To process form data and execute commands based on user input in PHP, you can use the $_POST superglobal array to access form data submitted via POST method. You can then use conditional statements to check the user input and execute specific commands accordingly.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$userInput = $_POST['user_input'];
if ($userInput == 'command1') {
// Execute command 1
} elseif ($userInput == 'command2') {
// Execute command 2
} else {
// Handle invalid input
}
}
?>