Skip to content
Related Articles

Related Articles

Improve Article

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

  • Last Updated : 24 Jun, 2021

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. 




<!DOCTYPE html>
    <!-- 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">
    // 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>";


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :