How to setup database for website

How to setup database for website. Database is the core of any web application. A database provides the storage space that allows your application to store and retrieve data. If a database is properly configured, it can essentially store almost any type of data.

Setup database for your website. This article will show you how to get started with a MySQL database, how to host a website with sql database and websites with databases examples.

How to setup database for website

Before you start building your web application or your database-driven website, you would need to create a database that will contain all of your data and permissions. The next guide will show you how to create an online database for your website or for your application, set up your tables, set your permissions, and how to control your future users.  

Simbla’s online database  is based on Parse server’s platform, wherefore you will enjoy all that Parse offers and lots more.

how to create a database for a website or for your application?

You can create your new database from two different areas:

1. The database control panel.

2. The page you are working on.

1. Database control panal

In order to create your new online database, go to your database control panel and click on “Create new database”.

Next, you will name your database and it will appear in your databases list.

For the next example and throughout the guide, we are going to use a database that includes a “user” table and a “car” table.

Clicking on a database from your list will open your new work area:

In the top toolbar you will find three tabs:

1. Users – View, create and edit all of your users. In the user tab you will be able to change each user’s permission separately and set  his roles.

2. Roles – Roles allow you to set groups of permission that can be given to users and tables, for example: site admins, editors, users, etc. In the roles tab you will be able to create and manage your roles and set their permissions.

3. Tables – Tables tab will take you to where you will control all of your database tables. Here you will be able to create, edit and delete tables and set permissions and roles to all of them separately.

2.  Create or Connect a database from your page

While editing you page in the website editor you can simply create and connect it to a database.

From the top left bar click on the database icon and select your database from the list that will open.

If you wish to create a new database you can do so from this window, once your new database is set, click on “go to database” to start editing it.

websites with databases examples

A database is a system that collects and stores data in electronic form. They go back to the 1970s, at the start of the information age. At that time, computer storage was a costly asset to most businesses. That’s why Edgar Codd coined an idea for handling records hassle-free by using a relational model.

The IBM engineer’s idea made it possible to use disk space more efficiently. His approach provided a straightforward way of managing data using cross-linked tables, simplifying storing and retrieving info from a central location.

However, it wasn’t until the 1990s that website databases came into existence. With this technology, organizations can manage large amounts of information effortlessly. It primarily covers websites and applications that are accessible from the internet.

A web-based database is just a system that stores information for online access. It usually keeps records in a way that’s easy to search and retrieve through a browser. An example is the search tool on TechJury. All you need to do is use various keywords to find the desired information.

Now, let’s see how it keeps data organized.

Data Organization

The organization of data in a web-based database is simple. Information is kept in tables that have different fields. Depending on the system, that can either be in relational or non-relational format.

The relational model is most common for records that share related fields. For example, a school’s set-up can have a wide range of student details with names, classes, and more. That way, the administrator can filter the info depending on their needs.

However, the non-relational option uses a random approach to organize information. It generates schema structures that are flexible and robust, which are useful for organizations that handle large amounts of records.

So, where is the data in a database stored?

Good question.

Once a system processes the records, it stores them in the root directory. It consists of a folder in a computer’s storage system.

Database software is also available to organize and correlate various sets of data. Most of it is usually in a natural processing language format, including text, numbers, and symbols. Altogether, it streamlines the process of sorting records for quick retrieval.

But where do they get the information?

While this varies depending on the needs of an organization, the majority rely on data analytics to gather info from multiple sources.

A good example is how Google works with search records from users. It additionally has a bot that crawls billions of informational websites on the web. From here, it ranks them depending on the most searched terms on the internet.

What about security?

Securing your website-based database is also of great importance, especially since hackers access billions of organizational records every year. Protecting your systems isn’t a matter that’s up for discussion; it’s a must.

Luckily, database management systems (DBMS) offer robust data encryption mechanisms. Top of that list is the use of complex algorithms for encrypting files. This approach makes information unreadable to unauthorized users. When you need access, it will decrypt the records to make them readable.

Passwords and private keys are great alternatives for securing your web database. These usually limit the people that can access the system. What’s more? It ensures hackers have a rough time trying to penetrate the website database.

A web application firewall (WAF) is another excellent option. It adds an extra layer of protection to your systems. The set-up works effectively in filtering bots, spam, and DDoS attacks. The best part – it’s available at an affordable cost from CDN providers.

What Is SQL

Before we dive in, let’s revisit the question “What is a database?”

It’s a system that helps organize data for quick access by storing records in tables with multiple fields. In doing so, you can use natural language to search and retrieve information.

And that’s where SQL comes into the picture.

The initials are the acronym for Structured Query Language. It provides a way of communicating with the database using simple commands, including “create,” “delete,” “update,” “insert,” and more.

What is a SQL Database?

In plain English, it’s a DBMS that uses the relational model to manage records. It’s part of Codd’s idea, which IBM developed in the 1970s. The company’s prototype included the IBM DB2. In 1979, Oracle Inc. advanced it further by releasing a commercial version.

At present, the technology powers approximately 40% of website databases. The figure is 10% higher than its closest rival, MongoDB. Other notable competitors include PostgreSQL, Redis, and Cassandra. Altogether, they trail their peers with figures of 17.4%, 8.4%, and 3.0%, respectively.

Such popularity is a result of being efficient and easy to use. Its top features include:

  • Fast processing of records
  • Extremely portable
  • Use of natural language
  • Multiple viewing of the database structure

Above all, it requires zero coding skills to use on the front-end. That’s why most content management systems (CMS) depend on it to power websites. For example, the WordPress database uses this DBMS to process data. Others that run on this system include Drupal, Joomla, and Magento.

Database Types

Other than the SQL database, there are six different types of database systems. Here’s a summary of them:

  • Distributed database: This system depends on multiple data warehouses for the storage and processing of records. It uses database replication to ensure uniformity of information across the different physical sites.
  • Cloud database: These are more modern databases that run in a virtual environment. They have a high computing power for processing unlimited records. Best of all – it offers instant upscaling of resources whenever the need arises.
  • NoSQL database: NoSQL is the exact opposite of SQL set-ups. They are perfect for handling large sets of unstructured data. As such, they run on the cloud across multiple servers for better efficiency.
  • Hierarchical database: Hierarchical DBMS stores information in a tree-like structure. With this method, data is kept in categories that expand to various subcategories. The approach supports the rational model for interlinking records.
  • Centralized database: This web-based database stores data in a central location. The configuration allows easy access of information by multiple users remotely. Furthermore, it’s easier to configure and manage.
  • Network database: Network databases are systems for managing enterprise operations. They are ideal for organizations that handle multiple relational datasets. These can include customers, transactions, staff, marketing, and so on.

It’s now time to wind up.

Wrap Up

Website databases are essential tools for organizing data. They provide a structured approach for storing and retrieving records. Apart from that, it requires zero coding knowledge to manage the systems. The robust database management software makes the tasks of creating, modifying, and deleting info intuitive.

The SQL web database is the most popular of all types. It’s fast, reliable, and highly flexible. What’s more? It uses natural language to process and handle information. For example, you can use commands such as “create,” “delete,” and “update.

how to host a website with sql database

How to connect HTML to database with MySQL using PHP? An example – This article helps to become a custom PHP developer. You will get complete steps for PHP database connection example program. This article provide you HTML form, DB + Table SQL code, Boostrap 5 with CSS, Form Validation and database connection +  submission code .  In the conclusion step, you will be GIT download link so no need to copy-paste the code.

Tools Required to connect HTML Form with MySQL Database using PHP

First of all, you must be install any XAMPP or WAMP or MAMP kind of software on your laptop or computer. With this software, you will get a local webserver i.e. Apache, PHP language, and MySQL database. The complete code is on Github and the download link is the last of this article.

In this article, my PHP, MySQL example is with database connection in xampp code.

Xampp Apache and MySQL on

After installation you need to on the Xampp see the image below:

After installation of any of these laptop or desktop software you need to check your localhost is working or not. Open your browser and check this URL http://127.0.0.1 or http://localhost/ . If this is working it means you have the local webserver activated with PHP/MySQL.

Also, GUI PHPmyAdmin coming for handling CRUD operations i.e. insert(create), update, delete, and select(read) records from tables. This interface is browser-based and very helpful, easy to use for creating and managing phpmyadmin database in table(column, row).

If you have the above installation you can go ahead to start your coding.

If you have not a LAMP stack-based web server then you can do this directly in your hosting space.

If you have any more query then you can comment on this post. We will reply to your query.

Suppose you have a web page to insert contact form field data in your DB. For this you need to follow the following steps:

Step 1: Filter your HTML form requirements for your contact us web page

Suppose you selected the form field Name (text input), Email(email input), Phone (number input), and message (multi-line text). The form submit button also necessary for submitting the form. You will get the complete form in HTML coding in step 3.

Step 2: Create a database and a table in MySQL

Open a web browser (chrome, firefox, edge, etc., ) and type this http://localhost/phpmyadmin/ or http://127.0.0.1/phpmyadmin/ for open GUI for managing DB on your computer. See the xampp screen below how it is coming.

Click on the databases link and create your db by the name “db_contact”. See the image below:

After creating your DB you need to create a table by any name I choose “tbl_contact” with the number of field 5. We choose 4 fields on top Name, Email, Phone, and Message. The first column we will keep for maintaining the serial number and in technical terms primary key(unique number of each recor). See the image below

When you will click to go button you will get this screen. Now we need to feed every field information.

See the below image in which I added field information. So for field Name used field Name – fldName, Email – fldEmail, Phone – fldPhone, Message – fldMessage.

Now click on the save button that is on the bottom right of your screen. After saving your table it is created in your database.


You can create your DB and table using the SQL below. You have to copy the following code and paste it into your MySQL GUI  phpmyadmin database or any other GUI or command prompt. At the bottom of the blog, you will get a git download link to download the SQL file.



--
-- Database: `mydb`
--

CREATE DATABASE IF NOT EXISTS `db_contact` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `db_contact`;

-- --------------------------------------------------------

--
-- Table structure for table `tbl_contact`
--

DROP TABLE IF EXISTS `tbl_contact`;
CREATE TABLE IF NOT EXISTS `tbl_contact` (
`id` int(11) NOT NULL,
`fldName` int(50) NOT NULL,
`fldEmail` int(150) NOT NULL,
`fldPhone` varchar(15) NOT NULL,
`fldMessage` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `tbl_contact`
--
ALTER TABLE `tbl_contact`
ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `tbl_contact`
--
ALTER TABLE `tbl_contact`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

Step 3: Create HTML form for connecting to database

Now you have to create an HTML form. For this, you need to create a working folder first and then create a web page with the name “contact.html”. If you install xampp your working folder is in folder this “E:\xampp\htdocs”. You can create a new folder “contact” on your localhost working folder. Create a “contact.html” file and paste the following code.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Form - PHP/MySQL Demo Code</title>
</head>

<body>
<fieldset>
<legend>Contact Form</legend>
<form name="frmContact" method="post" action="contact.php">
<p>
<label for="Name">Name </label>
<input type="text" name="txtName" id="txtName">
</p>
<p>
<label for="email">Email</label>
<input type="text" name="txtEmail" id="txtEmail">
</p>
<p>
<label for="phone">Phone</label>
<input type="text" name="txtPhone" id="txtPhone">
</p>
<p>
<label for="message">Message</label>
<textarea name="txtMessage" id="txtMessage"></textarea>
</p>
<p>&nbsp;</p>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit">
</p>
</form>
</fieldset>
</body>
</html>

Now your form is ready. You may test it in your localhost link http://localhost/contact/contact.html
In the next step, I will go with creating PHP / MySQL code.

Step 4: Create a PHP page to save data from HTML form to your MySQL database

The contact HTML form action is on “contact.php” page. On this page, we will write code for inserting records into the database.

For storing data in MySQL as records, you have to first connect with the DB. Connecting the code is very simple. The mysql_connect in PHP is deprecated for the latest version therefore I used it here mysqli_connect.

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

You need to place value for your localhost username and password. Normally localhost MySQL database username is root and password blank or root. For example, the code is as below

$con = mysqli_connect('localhost', 'root', '',’db_contact’);
The “db_contact” is our database name that we created before.
After connection database you need to take post variable from the form. See the below code
$txtName = $_POST['txtName'];
$txtEmail = $_POST['txtEmail'];
$txtPhone = $_POST['txtPhone'];
$txtMessage = $_POST['txtMessage'];

When you will get the post variable then you need to write the following SQL command.

$sql = "INSERT INTO `tbl_contact` (`Id`, `fldName`, `fldEmail`, `fldPhone`, `fldMessage`) VALUES ('0', '$txtName', '$txtEmail', '$txtPhone', '$txtMessage');"

For fire query over the database, you need to write the following line

$rs = mysqli_query($con, $sql);

Here is PHP code for inserting data into your database from a form.

<?php
// database connection code
// $con = mysqli_connect('localhost', 'database_user', 'database_password','database');

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

// get the post records
$txtName = $_POST['txtName'];
$txtEmail = $_POST['txtEmail'];
$txtPhone = $_POST['txtPhone'];
$txtMessage = $_POST['txtMessage'];

// database insert SQL code
$sql = "INSERT INTO `tbl_contact` (`Id`, `fldName`, `fldEmail`, `fldPhone`, `fldMessage`) VALUES ('0', '$txtName', '$txtEmail', '$txtPhone', '$txtMessage')";

// insert in database 
$rs = mysqli_query($con, $sql);

if($rs)
{
	echo "Contact Records Inserted";
}

?>

Step 5:  All done!

Now the coding part is done.  Download code from github

If you would like to check then you can fill the form http://localhost/contact/contact.html and see the result in the database. You may check via phpmyadmin your inserted record.

Leave a Comment