PHP and MySQL (55 Blogs) Become a Certified Professional

Everything About Data Retrieval In PHP

Published on Jul 18,2019 1.1K Views

We need a database which is a collection of the tables to store the data in it which is entered by the user. This article will brief you on can creation of database and Data Retrieval In PHP.

Let us get started with the first of this article on Data retrieval in PHP,

How To Create A Database 

Step1: Open localhost dashboard and click on phpMyAdmin

Create BD - Data Retrieval In PHP - Edureka

Step2: Now create a database either through a query or manually. In order to do it manually, click on databases and create a new one.

Create BD - Data Retrieval In PHP - Edureka

Step3: Now create a table with columns as per our requirements for the website. As we are going to discuss how to design a feedback form using PHP, we just need to enter the name and feedback so we will just create a table with 2 columns.

Step4: Click on SQL and write a query for creating a table with the columns

Create BD - Data Retrieval In PHP - Edureka

 Moving on to the second bit of this article

Data Retrieval In PHP: PHP Code For The Feedback Form

Write this code in a notepad file and save it in htdocs and go to the localhost dashboard and run this 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" "">
<html xmlns="">
<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>"The key to learning is feedback.It is nearly impossible to learn anything with out it"</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()">

Create BD - Data Retrieval In PHP - Edureka

After submitting the feedback, you can see the changes in the table under the database.

Create BD - Data Retrieval In PHP - Edureka

This bring us to the final bit of this article,

PHP Code For Data Retrieval From The Database

You can code it out in this way to fetch the feedbacks which 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

And there you go

Create BD - Data Retrieval In PHP - Edureka

With this we come to an end of this article on Data Retrieval In PHP, I hope you have learned about  how to create a Database and store the data obtained from the form which is entered by a user and fetching the user data from the database.

If you found this Data Retrieval In PHP article relevant, check out the PHP Certification Training by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.

Got a question for us? Please mention it in the comments section of  this article and I will get back to you.


Join the discussion

Browse Categories

webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.