Swati Lathia

Learning ways

Database Connectivity

We have already learnt form element in our HTML tutorial. Since we understand that HTML only shows you how your form look like, it can not store/save your data for future reference. We can not edit or delete that data without storing anywhere. We all know that PHP enhances our website with its better connectivity to database. Here, we are using PHP with MySQL tool (phpmyadmin). For this, you just need web server (here we are using WAMP server). So let’s start with simple example of student detail.

We have created our database in phpmyadmin with database name “db_student“. Table inside this database is “tbl_stud_detail“. All the fields are : stud_id integer(5) Primary Key Auto Increment, stud_name varchar(50), stud_city varchar(50), stud_age integer (3)

After creating the table, now we are start creating HTML form from which we can insert data to tbl_stud_detail.

The following file is “stud_insert.html

<form method=post action="stud_insert.php">
	Enter Student Name :<input type=text name=t1><br>
	Enter Student City :<input type=text name=t2><br>
	Enter Student Age :<input type=number name=t3><br>
	<input type=submit name=s1><br>

Now create “stud_insert.php” file to connect it with database

//Fetch all the values from HTML form elements 

//Connect with server & phpmyadmin database 

//Insert query to insert record into table
$insert_qry="INSERT INTO `tbl_stud_detail` 

//Execute/Send the query to phpmyadmin

/*After sending insert query this page redirects to stud_data.php where a tabular format of data is displayed */

Now create “stud_data.php“. This page shows you the inserted records in a tabular format.


//Connection & database selection

//Select required columns from table
$select="select * from `tbl_stud_detail`";

echo "<table border=2>
	<th>Student Id</th>
	<th>Student Name</th>

//This while loop executes till the record is in the resultset (result returned from SELECT query)
        echo "<tr>

echo "</table>";
echo "<br><a href='stud_insert.html'>Add another record</a>";

This is how you can insert any data from HTML form to your phpmyadmin database table & fetch them in your webpage as per your requirement in a tabular form.

Database connectivity Videos

Creation of Database and table in MySQL (phpmyadmin)

How to fetch the record from Database table to Your webpage/browser

How to delete record from Database table

How to update record(s) in database table

Select query Example (fetching records from table)

Scroll to top