Using PHP GET and POST function you can Enter your data and display it. There are two ways to get information from users by creating Simple form and using GET and POST methods. Today I will give an Example of POST function and GET function.
READ MORE :- How to Create Dynamic Website With PHP
POST method
STEP 1 :- Create folder in htdocs and create two pages such as Index.php and welcome.php
STEP 2 :- In Index.php Page paste the below code :
<html>
<body><form action=”welcome.php” method=”post”>
Name: <input type=”text” name=”fname”><br>
Age : <input type=”text” name=”age”><br>
<input type=”submit”>
</form></body>
</html>
STEP 3 :- Now open Welcome.php page and paste the below Code :
<html>
<body>Welcome <?php echo $_POST[“fname”]; ?>!<br>
You are <?php echo $_POST[“age”]; ?> years old.</body>
</html>
GET method
STEP 1 :- Create folder in htdocs and create two pages such as Index.php and welcome.php
STEP 2 :- In Index.php Page paste the below code :
<html>
<body><form action=”welcome.php” method=”get”>
Name: <input type=”text” name=”fname”><br>
Age : <input type=”text” name=”age”><br>
<input type=”submit”>
</form></body>
</html>
STEP 3 :- Now open Welcome.php page and paste the below Code :
<html>
<body>Welcome <?php echo $_GET[“fname”]; ?>!<br>
You are <?php echo $_GET[“age”]; ?> years old.</body>
</html>
Difference between GET and POST method
Have you Seen the difference between GET function and POST Function, If not then Just see the URL of both welcome.php page.
–> Using GET function is not secure Since your Information will appear in URL address. In GET function you can transfer limited data.
–> Using POST function is secure Since your Information will not appear in URL address. In POST function you can transfer Unlimited data.
Contents
- 1
- 2 POST method
- 2.0.1 <html> <body>
- 2.0.2 <form action=”welcome.php” method=”post”> Name: <input type=”text” name=”fname”><br> Age : <input type=”text” name=”age”><br> <input type=”submit”> </form>
- 2.0.3 </body> </html>
- 2.0.4 <html> <body>
- 2.0.5 Welcome <?php echo $_POST[“fname”]; ?>!<br> You are <?php echo $_POST[“age”]; ?> years old.
- 2.0.6 </body> </html>
- 3 GET method
- 3.0.1 <html> <body>
- 3.0.2 <form action=”welcome.php” method=”get”> Name: <input type=”text” name=”fname”><br> Age : <input type=”text” name=”age”><br> <input type=”submit”> </form>
- 3.0.3 </body> </html>
- 3.0.4 <html> <body>
- 3.0.5 Welcome <?php echo $_GET[“fname”]; ?>!<br> You are <?php echo $_GET[“age”]; ?> years old.
- 3.0.6 </body> </html>
- 3.1
- 3.2 Difference between GET and POST method