What is the correct way to send information from an HTML form to a PHP script?
To send information from an HTML form to a PHP script, you can use the POST method in the form tag and set the action attribute to the PHP script's file path. In the PHP script, you can access the form data using the $_POST superglobal array. Make sure to sanitize and validate the input data to prevent security vulnerabilities.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
// Sanitize and validate the input data
$name = filter_var($name, FILTER_SANITIZE_STRING);
$email = filter_var($email, FILTER_VALIDATE_EMAIL);
// Process the form data further
}
?>