Q:

PHP program to demonstrate the use of $_POST superglobal variable

belongs to collection: PHP Miscellaneous

0

Here, we will demonstrate the use of the $_POST superglobal variable by creating a submit button using the post method with the help of a form tag.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to demonstrate the use of the $_POST superglobal variable is given below. The given program is compiled and executed successfully.

<html>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  Enter country name: <input type="text" name="country">
  <input type="submit">
</form>

<?php
//PHP program to demonstrate the use 
//of $_POST superglobal variable.
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    $country = $_POST['country'];
    printf("Country Name: %s<br>", $country);
}
?>

</body>
</html>

Output:

o/p

Explanation:

In the above program, we create a form tag with the post method that contains an input field and a submit button.

if ($_SERVER["REQUEST_METHOD"] == "POST") 
{
    $country =$_POST['country'];
    printf("Country Name: %s<br>",$country);
}

In the above code, we checked the request method using $_SERVER superglobal, then we get the value of the input field using $_POST superglobal and then printed the country name using printf() function on the webpage

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Miscellaneous

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
<< PHP program to demonstrate the use of $_REQUEST su...