Click here to Skip to main content
15,916,318 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to connect MySQL database in my HTML page. I want to insert and retrieve data using MySQL database which I have created using phpMyadmin in WAMP server. How can it possible using HTML 5. I saw many examples for creating table and insert, delete etc. But first I have to connect the database to my HTML page. Then insert data into the database and retrieve data from it. I also want to connect a remote database in my HTML page. I searched on google and none of them helped me. If you have any idea, please share.

Thank you....
Updated 7-Dec-17 19:03pm
Mohibur Rashid 11-Aug-12 13:47pm    
what was the search string you used?

and besides, you cannt connect mysql with html you need to use php

1 solution

I think you can't connect MySQL database in html page directly but there is some way to hiding the backhand/server side scripting code's and display html pages. now I am talking about php(because of WAMP).
Create a php file first to make connection to mysql
for example connect.php
$host="localhost"; // Host name.
$db_user="root"; // MySQL username.
$db_password=""; // MySQL password.
$database="test"; // Database name.
$link = mysql_connect($host,$db_user,$db_password);
if (!$link) {
   die('Could not connect: ' . mysql_error());
echo "Mysql Connected Successfully";


and Create a Index.html using ajax
<script type="text/javascript">
function checkmyconnect()
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
<h2>Let Connect to mysql in html file</h2>
<div id="myDiv">No connection</div>
<button type="button"  önclick="checkmyconnect()">Check Mysql connection</button>


and test now
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900