The Wayback Machine - https://web.archive.org/web/20240118180309/https://www.geeksforgeeks.org/how-to-create-html-form-that-accept-user-name-and-display-it-using-php/
Open In App
Related Articles

How to create HTML form that accept user name and display it using PHP ?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Through HTML forms various data can be collected from the user and can be sent directly to the server through PHP scripting. There are basically two methods for sending data to the server one is “GET” and the other one is “POST”.

In GET method, the data goes through the browser’s URL and can be seen by anyone using the browser, and it is not very safe when sending crucial or highly confidential data. But with the POST method, the data is directly sent to the server, and it can’t be seen by anyone, and it is considered the most secure way to send the information to the server. 

Generally, the GET method is used by the search engines because it reads the data but for the data to be maintained or changed, the POST method is used for it.

Approach: We will see one example of the HTML form collecting the first and last name of the person and sending the data to the DOM which eventually displays the data on the screen using PHP script. 

 

Example:

HTML




<!DOCTYPE html>
<html>
  
<body>
    <!-- Heading -->
    <h3> HTML input form </h3>
  
    <!-- HTML form  -->
    <form method="POST">
        <h4>Please enter your First Name : </h4>
        <input type="text" name="f_name"><br>
        <h4>Please enter your Last Name : </h4>
        <input type="text" name="l_name"><br><br>
  
        <input type="submit" value="Display" name="submit">
    </form>
</body>
  
</html>
<?php
      
    // When the submit button is clicked
    if (isset($_POST['submit'])) {
      
        // Creating variables and 
        // storing values in it
        $f_name = $_POST['f_name'];
        $l_name = $_POST['l_name'];
  
        echo "<h1><i> Good Morning, $f_name $l_name </i></h1>";
    }
?>


Output:


Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 24 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials