Live Chat

Domain Scan

(empty)

Login


Database Guide: How to Create and Insert Data to a Database

Database Guide: How to Create and Insert Data to a Database
(25-jun-2025)

Illustration of a database with cloud upload arrow

Every modern website relies on a database-it's the silent engine that stores everything from user details and form submissions to product listings and blog content. Whether you're running a small portfolio or a growing online platform, having a database working in the background ensures your data is organized, accessible, and secure. With the right tools, you can take control of your website's data and unlock features that make your site smarter, faster, and more dynamic.



How Databases Can Power Your Website - and Why It Matters

Databases form the backbone of any dynamic website or online application. Whether you're building a contact form, managing product listings, tracking orders, or storing newsletter signups, a database lets you organize, store, and retrieve data in real time. By connecting your website to a database through backend programming (like PHP, Node.js, or Python), you can make your content interactive and data-driven.

You're not limited to one type of data. You can create multiple databases-one for customer information, another for orders, another for blog posts, and so on. Each can have its own tables and structure based on your specific needs.


Why Use Databases on Your Website?

  • Dynamic Functionality: Display personalized or changing content without editing static pages.
  • Scalability: Handle thousands of entries or users with ease.
  • Data Control: Add, update, or delete records anytime through SQL or your app's backend.
  • Separation of Logic and Design: Keep your data and interface separate, which simplifies maintenance.
  • Enhanced Features: Enable search, login systems, dashboards, and reporting tools seamlessly.

Whether you're building a portfolio site, an eCommerce platform, or a custom web application, a well-structured database will give you the power to grow and adapt your project efficiently.

In this step-by-step guide, we'll walk you through how to set up your own database, create a table to store customer information, and insert and view that data using both the phpMyAdmin interface and SQL queries. Let's dive in and bring your data to life!



Step 1: Create a New Database from cPanel

  1. Log in to cPanel

    Access your cPanel at yourdomain.com/cpanel with your hosting credentials.

  2. Scroll down to the Databases section.
  3. Click on Manage My Databases.
  4. Under Create New Database, enter a name like customer_db.
  5. Click Create Database.
  6. Creating a new MySQL database in cPanel using the Manage My Databases section

Once created, scroll down to add a new user:

  1. Enter a Username and Password under "MySQL Users."
  2. Click Create User.
  3. Adding a new MySQL user in cPanel with username and strong password

Then assign the user to the database:

  1. Under Add User to Database, choose the newly created user and database.
  2. Click Add, then select All Privileges, and click Make Changes.
  3. Assigning a MySQL user to the newly created database in cPanel


Step 2: Access phpMyAdmin

  1. Go back to the main cPanel dashboard.
  2. Click on phpMyAdmin under the Databases section.
  3. In phpMyAdmin, select the newly created database (customer_db) from the left sidebar.


Step 3: Create a Table in the Database

Method 1: Using phpMyAdmin Interface

  1. In the selected database, find the Create table section.
  2. Enter table name: Customers
  3. Set number of columns: 4
  4. Click Create
  5. Creating a new table named 'Customers' in phpMyAdmin with 4 fields
  6. Configure the fields:
  7. Defining columns for the 'Customers' table with email as the primary key

Method 2: Using SQL Query in phpMyAdmin

Click on the SQL tab and run:

CREATE TABLE customers (
    email VARCHAR(100) PRIMARY KEY,
    name VARCHAR(100),
    phone VARCHAR(15),
    city VARCHAR(50)
);

Feel free to modify the number of fields, field names, data types, and lengths based on the kind of data you intend to store.


What is a Primary Key: A primary key uniquely identifies each row in the table. In this case, the email field ensures no duplicate entries are allowed for customers.



Step 4: Insert Data into the Table

Method 1: Using phpMyAdmin Interface

  1. Click the customers table from the left panel.
  2. Open the Insert tab.
  3. Fill in sample customer details:
    • email: john@example.com
    • name: John Doe
    • phone: 0771234567
    • city: Colombo
  4. Click Go to save the entry.
  5. Inserting a customer record into the 'Customers' table via phpMyAdmin interface

Method 2: Using SQL Query

Navigate to the SQL tab and run:

INSERT INTO customers (email, name, phone, city)
VALUES ('john@example.com', 'John Doe', '0771234567', 'Colombo');

You can use SQL queries in your website's backend code to insert, update, or delete data in your database tables.



Step 5: View the Stored Data

Method 1: Using phpMyAdmin Interface

  1. Click the Browse tab on the top menu.
  2. Your saved customer records will appear in a table format.
  3. Viewing inserted customer data in phpMyAdmin under the Browse tab

Method 2: Using SQL Query

To fetch all records, run:

SELECT * FROM customers;

Your database is now fully set up-you've created it, added a table, inserted data, and viewed it successfully.


Note: Once your database is set up, you can add more tables, edit records, or customize the structure through phpMyAdmin or SQL queries to suit your needs. You can also connect it to your website using backend scripts to handle dynamic content, user interactions, and more.



Conclusion

Setting up a database might seem technical at first, but with cPanel and phpMyAdmin, the process becomes simple and accessible-even for beginners. Whether you're managing customer details, handling product records, or preparing for future website features, having a structured database is essential. By learning to create tables, insert data, and run SQL queries, you're taking a solid step toward building more powerful, dynamic websites. Keep exploring, and let your data work for you!


BACK 2 BLOG