Site icon WDB24

Retrieve data from database and display in php form

php featured image

As we already see “how to insert data in mysql using php form“. But if want to edit some information in that form how will I do that? Should I directly update form without seeing the previous data? Or should I check my previous data first and then update specific data?

Answer is obvious that first I have to look at previous data then I will update that. But how to get data and display in form

Don’t worry in this post I am going to show how to retrieve data from database and display in php form.

I am taking my previous example of insert data. In that post I created a form with title and content field only. So this time I am not going to create database and table because i already created both of them in my previous post. Now let’s start

Create database connection:

Retrieve Data from Database:

In above php code I get the row which id is 1. mysqli_fetch_assoc() function will return that specific row as an array (which holds title and content) and I store that array in $fetchRow variable.


Now I get the row from the database it’s time to show each column data into its respective fields.

After that above changes your form will look like this.

Apply CSS:

All Together

Exit mobile version