In PHP GET and POST superglobals are used to collect form-data.
Page Contents
In our first example program, we will create a search web page using the get method. let’s start with the search page example.
Example Program:
<?php
if(isset($_GET["submit"])){
echo "<h2>Your are searching for " . $_GET["search"] . "</h2>";
}
?>
<html>
<body>
<form method="GET">
<input type="text" name="search" placeholder="Search Product Here"><br>
<input type="Submit" name="submit">
</form>
</body>
</html>
As you can see in the above example how we create a search page using the GET method. (In this tutorial we are not using any database but don’t worry in MYSQL tutorials we will also perform search operations in the database using PHP)
In our next example program, we will create a login form using the POST method. Please keep in your mind we always use the POST method for login, and signup pages because we don’t want to show user data in the URL bar. (Here we will use a static username and password value but in the MySQL tutorial, we will perform the login by searching the user from the database)
Example Program: –
<?php
$valid_email="admin@xyz.com";
$valid_password="123";
if(isset($_POST["submit"])){
$email=$_POST["email"];
$password=$_POST["pass"];
if($valid_email==$email&&$valid_password==$password){
echo "<h2>Welcome, your are a valid user</h2>";
}
else{
echo "<h2>Please check your email and password</h2>";
}
}
?>
<html>
<body>
<form method="POST">
<input type="text" name="email" placeholder="Please Enter Your Email"><br>
<input type="password" name="pass" placeholder="Please Enter Your Password"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
As we created this login page in the same way you can create a signup page using the POST method.
Parvesh Sandila is a results-driven tech professional with 8+ years of experience in web and mobile development, leadership, and emerging technologies.
After completing his Master’s in Computer Applications (MCA), he began his journey as a programming mentor, guiding 100+ students and helping them build strong foundations in coding. In 2019, he founded Owlbuddy.com, a platform dedicated to providing free, high-quality programming tutorials for aspiring developers.
He then transitioned into a full-time programmer, where his hands-on expertise and problem-solving skills led him to grow into a Team Lead and Technical Project Manager, successfully delivering scalable web and mobile solutions. Today, he works with advanced technologies such as AI systems, RAG architectures, and modern digital solutions, while also collaborating through a strategic partnership with Technobae (UK) to build next-generation products.
