post
This code is an example of using the $_POST superglobal array in PHP to handle data sent from an HTML form using the "post" method. The $_POST array is used to collect data from an HTML form using the "post" method or to retrieve data from an API.
The code includes an HTML form with two input fields, one for the name and one for the email, and a submit button. When the user fills in the form and clicks the submit button, the form sends a POST request to the server, which includes the input field data as part of the request body.
The PHP code then uses an if statement to check if the form is submitted by checking if the submit button is set using the isset() function. If the form is submitted, the code will use the $_POST array to get the values of the name and email fields and save them to variables.
Finally, the script will display the name and email on the page by echoing the values of the variables.
It is worth noting that the $_POST array is more secure than the $_GET array as the data sent in the request body is not visible in the URL and is less likely to be modified by the user.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>html form</p>
<form action="post.php" method="post">
<input type="text" name="name" placeholder="name">
<input type="text" name="email" placeholder="email">
<input type="submit" name="submit" value="submit">
</form>
<?php
// check if the form is submitted
if(isset($_POST['submit'])){
// get the form data
$name = $_POST['name'];
$email = $_POST['email'];
// display the form data
echo "Your name is: $name and your email is: $email";
}
?>
</body>
</html>