12

I want to know how to connect html pages to mysql database? What are the codes?

I also want to know how to add new data to MySQL database when I'm using HTML page and also how to publish the data?

1
  • 4
    it is not possible from html. you must use server side scripting language to do that like php or asp or any Commented Feb 16, 2011 at 3:51

1 Answer 1

31

HTML are markup languages, basically they are set of tags like <html>, <body>, which is used to present a website using , and as a whole. All these, happen in the clients system or the user you will be browsing the website.

Now, Connecting to a database, happens on whole another level. It happens on server, which is where the website is hosted.

So, in order to connect to the database and perform various data related actions, you have to use server-side scripts, like , , etc.

Now, lets see a snippet of connection using MYSQLi Extension of PHP

$db = mysqli_connect('hostname','username','password','databasename'); 

This single line code, is enough to get you started, you can mix such code, combined with HTML tags to create a HTML page, which is show data based pages. For example:

<?php $db = mysqli_connect('hostname','username','password','databasename'); ?> <html> <body> <?php $query = "SELECT * FROM `mytable`;"; $result = mysqli_query($db, $query); while($row = mysqli_fetch_assoc($result)) { // Display your datas on the page } ?> </body> </html> 

In order to insert new data into the database, you can use phpMyAdmin or write a INSERT query and execute them.

Sign up to request clarification or add additional context in comments.

2 Comments

I wonder if anyone has tried this answer.
@carloswm85, LOL. Add a warning if you want to.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.