PHP code to display MySQL data in an HTML table

By | July 19, 2016

A simple HTML form containing fields – Name, Address Line1, Address Line2, and E-mail. On submitting the form, the data is inserted into MySQL table using PHP code. We will iterate over each record present in the table to display MySQL data in an HTML table.

 

 

 

The following image shows how the UserData.html looks on the browser:
HTML form to insert data in to MySQL table

 

Suggested Read:

 

 

The following image shows how the Display.php looks on the browser:

PHP code to display MySQL data in an HTML table

display MySQL data in an HTML table


How to execute this code?

  1. You need to copy files UserData.html and Display.php to a PHP server. You can use wampserver software which provides an integrated environment to run PHP files along with the MySQL database server.
  2. Next, open this HTML file in the browser via localhost URL. Usually http://localhost/UserData.html
  3. Enter user details and submit the data.
  4. You should be able to see the results displayed on the same browser via Display.php file.
Suggested articles for you:

2 thoughts on “PHP code to display MySQL data in an HTML table

  1. Ganeswari

    It helps.But the above code has a mid error in file “display.html” in line 40,41,42,43

    Instead of this,use

    Pls correct it and post.Thank u so much

    Reply
    1. Ravi Bandakkanavar Post author

      Hi Ganeswari,

      This is a tested code. There is nothing wrong with the statement.
      echo $array[0]

      There should be some data in the table for this to work. Is there data in the table?

      Reply

Did it help? Comment here..

This site uses Akismet to reduce spam. Learn how your comment data is processed.