PHP program to demonstrate the use of $_POST superglobal variable

Here, we are going to demonstrate the use of $_POST superglobal variable in PHP.
Submitted by Nidhi, on November 24, 2020 [Last updated : March 14, 2023]

$_POST Superglobal Variable Example

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.

PHP code to demonstrate the example of $_POST superglobal variable

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


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

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





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

    $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.

More PHP Programs »


Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.