Data Retrieval In Php

Brief About Data Retrieval in PHP

Brief About Data Retrieval in PHP

To store the data entered by the user, we require a database, which is a collection of tables. This article will go over database creation and Data Retrieval in PHP.

How to create a database

Step 1 : Go to the localhost dashboard and click on phpMyAdmin


Step 2 : Create a database with a query or manually. If you go with the manual, click on databases to create a new database.

Create A Database

Step 3 : Create a table with columns based on our website requirements. We only need to enter the name and feedback because we are going to discuss how to design a feedback form using PHP, so we will just create a table with two columns.

Step 4 : Click on SQL to write a query and create a table with columns

Create A Table With Columns

Now, we have successfully created a database and a table in SQL

Data Retrieval in PHP

Following is the code that performs data retrieval. Copy this code in a notepad and go to the localhost dashboard and execute the code.



// connect to mysql

$con= mysqli_connect(“localhost”, “root”, “”,”feedback”);

//In case of failure connection



die(“Server could not connected”);


//After clicking on submit, those values get inserted into the table named as data which is located in feedback database.





//mysql insert query

$sql=”insert into data values(‘”.$name.”‘,'”.$feed.”‘)”;





<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “<a href=””></a>”>

<html xmlns=”<a href=””></a>”>


<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

<title>Feedback | Ashok Kumar |</title>

<meta name=”distribution” content=”global” />

<meta name=”language” content=”En” />



// function for creating alert after submission of feedback

function check()


alert(‘Thank you for your feedback.’);



<div class=”container”>

<form id=”contact” action=”” method=”post”>

<h3>Feedback Form</h3>

<h4>”Learning will never end without feedback “</h4>


<input placeholder=”Your name” type=”text” name=”name” tabindex=”1″ required autofocus>



<textarea placeholder=”Write Something about me..” name=”feed” tabindex=”5″ required autofocus></textarea>



<input type=”submit” name=”btn” value=”Submit” onclick=”check()”>




Feedback Form


Once the feedback submission is completed, we can see the changes in the table of the database.


Data Retrieval from the database using PHP

The following code will be useful for you to bring the feedback that is submitted.


// connect to mysql

$conn= mysqli_connect(“localhost”, “root”, “”,”feedback”);

if(! $conn )


die(‘Could not connect: ‘ );


// mysql select query

$sql = ‘SELECT name,feed FROM data’;


if(!$n )


die(‘Could not get data: ‘);


while($row = mysqli_fetch_array($n, MYSQLI_ASSOC))


echo “{$row[‘name’]} “. ” : {$row[‘feed’]} <br> “;


//closing connection with server





This is how data retrieval can be performed using PHP and SQL. Learn more about web development in our PHP Training in Chennai at Softlogic Systems.

Leave a Comment