Welcome to Techno Smarter QA, Question, Answer forum. Ask questions, receive answers, or help someone. Join Now
Welcome to Techno Smarter Q&A, where you can ask questions and receive answers from other members of the community. Ask the Technical & Programming related questions that you want. Join our community and help others .
+4 votes

Hey Community! 

I am the learner of PHP programming. I have completed HTML language and now I am trying to learn the PHP language. I want to connect the HTML page to PHP with the MYSQL database.  I tried many times to connect a simple HTML page to PHP but did not get any results. I can create HTML web pages but I don't know how can connect HTML page to PHP. I know about the MYSQL database but I don't know connection between HTML and PHP. I am a fast learner . Please give me the best solution to connect the HTML page with PHP using the MYSQL database. 

in PHP by (2k points) 8 18 40

2 Answers

+1 vote

PHP is one of the best and most used programming languages in the current time. HTML stands for a hypertext markup language. HTML designs the structure of the website. You can not connect HTML without PHP programming and MYSQL database. PHP stands for Hypertext preprocessor. It's used to create functionality for the website. We use PHP to connect simple HTML pages to the MYSQL database. I would like to suggest to understand the MYSQL database. MYSQL is used to create a database structure. 

How to connect HTML pages with the database using PHP?

The HTML page can be connected with the database using PHP programming language and MYSQL queries. You have understood the MYSQL queries before connecting HTML page to the database using PHP. 

Step 1- First of all install the xampp and wamp server on your computer. Xampp and wamp are local servers. Here we will use xampp server to connect a simple HTML web page to the database. 

xampp-wamp-local server global server

Download and install the xampp server on your computer. You can check the complete reference for xampp local server configuration. 

How to download and Install Xampp local sever?

Step 2- In this step, you have to create a database on localhost/phpmyadmin/    PHP admin panel and create a table inside the database name. 

I. Create a new database. 

II. Create a table inside the database. 

To connect the HTML page to the MYSQ database using PHP, you have to create a table. You can create an MYSQL table manually or use the query below. 

Create a table using the query below- 

CREATE TABLE  `user` (

 `id` INT( 40 ) NOT NULL ,

 `uname` VARCHAR( 30 ) NOT NULL ,

 `upassword` VARCHAR( 40 ) NOT NULL


Step 3- We will use an HTML form to connect the database using PHP. Here we will create a simple login form in PHP . To connect HTML form to the database, we insert some data in the database table. You can use the signUp system to create a new user or insert it manually using the query. 

INSERT INTO `user`(`id`, `uname`, `upassword`) VALUES (1,'demo','[email protected]');


Password = [email protected]

Step 4- Now, create an HTML form. We will connect HTML form to the database using a PHP script. 

<form action="" method="POST">

<b>Username:-</b><input type="text" name="uname" required=""><br><br>

<b>Password:-</b><input type="text" name="upassword" required=""><br><br>

<input type="submit" name="sub" value="Login">


Step 5- Now create a connection file. A connection file writes in the PHP script. This connection file is used to connect the HTML page to MYSQL database. 

Create a connection file and save as - config.php 


$databaseHost = '';//or localhost

$databaseName = 'test'; // your db_name

$databaseUsername = 'root'; // root by default for localhost 

$databasePassword = '';  // by defualt empty for localhost

$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName);



Step 6- Now create PHP script to connect HTML pages . 

In the PHP script , we use many pre-defined functions. These functions are known as built-in functions in PHP





$uname = $_POST['uname'];

$upassword = $_POST['upassword'];

$res = mysqli_query($mysqli,"select* from user where uname='$uname'and upassword='$upassword'");




echo "You are login Successfully ";

//header("location:my-account.php");   // create my-account.php page for redirection 




echo "failed ";




We can create HTML form and PHP script in the same page or different pages. 

Now, you can log in.In this way, you can connect simple HTML web pages to the MYSQL database using PHP. 

References - 

Login system in PHP

Signup system in PHP

CRUD application in PHP 

by (9.1k points) 11 25 63
+1 vote

First of all you need to install xamp, wamp or mamp any software required to be installed in your system with the help of which you will get a local web server apache. Once it is installed, you need to check whether localhost is working properly or not. The first step is to filter out your HTML form requirements, then need to create database. In this section, open the web browser and type http://localhost/phpmyadmin for open GUI for managing database on your computer. Click on database link and create database by name and then create a table with any number. Now create a HTML form and once form is created, then the next step is to create php or MYSQL code.

Now suppose you have created database db_contact, table tbl_contact, create web page with name of contact.htm, then in the last we will create php page. contact.php page includes contact HTML form action where you will write code for inserting record in database. For connecting database, the following code is very simple.

   $con= mysqli_connect("localhost", "your_localhost_database_user",     "your_localhost_database_password", "your_localhost_database_db");

Normally the localhost mysql database username is root and password is either blank or root.

For Xamp, the code is as below:

$con= mysqli_connect('localhost', 'root', '', 'db_connect');

where db_connect is the database name. After the connection of database, you need to take post variable from the form

$txtname= $_POST['txtname'];

$txtEmail= $_POST['txtemail'];

$txtPhone= $_POST['txtphone'];

$txtMessage= $_POST['txtmessage'];

by (190 points) 1 4