All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

How To Retrieve Data From Database In HTML Form

Last Updated : Mar 11, 2024

How To Retrieve Data From Database In HTML Form

In this tutorial we will show you the solution of how to retrieve data from database in HTML form, first here we want to say that this all can be done with the help of php.

So, you must have a basic knowledge of php, mysql, html and css. Here, today our topic is how to retrieve data from database in html form.

Step By Step Guide On How To Retrieve Data From Database In HTML Form :-

Now, for this you have to first make a connection with database. After this apply a query to fetch data from database.

And the last task is to present data in form. So, indirect a form must be created inside your php webpage.

<?php
    $connect=mysqli_connect("localhost","root","","as1") or die("Connection failed");
?>
<html>
    <head>
        <title>
            display data from database
        </title>
    </head>
    <body>
       <form action="" method="post">
        <?php
        $query = " select * from agedata";
        $result = mysqli_query($connect, $query);
        while ($row = mysqli_fetch_assoc($result)) {
        ?>
            <label for="">
                Name
            </label>
            <input type="text" value="<?php
                                        echo $row['Username'];
                                        ?>">
            <br><br>
            <label for="">
                Age
            </label>
            <input type="text" value="<?php
                                        echo $row['Age'];
                                        ?>">
            <br><br>
        <?php
        }
        ?>
    </form>
    </body>
</html>
  1. Here, first we already say you that you have to create a file which is saved with .php extension. This article can only done with the help of php.
  2. Next, already have a database in which there must be data inside that.
  3. This data we have to show on php form.
  4. Now, as shown in codes, we create a connect variable with the help of which we make a connection to database. If connection is not established then it show connection failed on web browser.
  5. In next step, we start html document. In this we create head, title, and body and use php inside body tag.
  6. Without wasting more time, let us understand body. In body, we create a form with post method, if you don’t know about how to make form that must visit webpage in which we show you how to make form.
  7. Inside form, we continue the process of fetching data from database and showing in html form, in form we use input type text to show data.
  8. In query, we select data from database and in result we make a connection between server and table.
  9. Now, we have to fetch data from database and show in on browser with the help of input tags. For this we create input tag and inside them we use php.
  10. In input, php codes are used to show data which we fetch from database.
  11. And at last he body tag and html tags gets closed. In next session, we will show you how to display data in html with the help of table.

Conclusion :-

In conclusion, here we can say that we hope now you can understand the way with the help of which you are able to retrieve data from database in html form tag.

In next session, we will show you how to retrieve data from database in html table. I hope this tutorial on how to retrieve data from database in HTML form helps you.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪