PHP Admin Set up

Set up a PHP admin panel involves several steps. An admin panel is a web-based interface used to manage and control various aspects of a website or web application.

In this tutorial, We will set up the basic configuration of the admin panel such as PHP configuration, database connection, admin table creation & directory structure

Steps to Set up Admin Panel

Now, You have to follow the below steps to set up the admin panel

1. Install Xampp Server

First of all, Make sure, xampp server is already installed in your system. if it is not then you must install its latest version (PHP 8.1>) from its official website ‘apachefriends.org’

2. Create a MySQL Admin Table

First of all create a database with the name ‘php-admin-panel’

CREATE DATABASE php-admin-panel

Now, create a table ‘admins’ in the created database.

CREATE TABLE your_table_name (
    id INT(10) AUTO_INCREMENT PRIMARY KEY,
    firstName VARCHAR(50) NOT NULL,
    lastName VARCHAR(50) NOT NULL,
    gender VARCHAR(10) NOT NULL,
    emailAddress VARCHAR(50) NOT NULL,
    mobileNumber VARCHAR(20) NOT NULL,
    pass VARCHAR(100) NOT NULL,
    status TINYINT(1) NOT NULL,
    created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
    updated_at DATE,
    INDEX (emailAddress)
);

3. Create an Admin Directory Structure

Create a basic directory structure

php-admin-panel/
    |__admin/
    |   |__public/
    |   |    |__css/
    |   |    |   |__custom.css
    |   |    |__js/
    |   |__scripts/
    |   |__views/
    |   |__index.html
    |__database.php

4. Set up Database Connection

Now, use the following code to connect the admin panel to the MySQL database.

This code is used to connect to a MySQL database from a PHP script, and it checks for a successful connection. If the connection fails, it will display an error message and terminate the script. It’s important to replace the variables with your database connection details

<?php

$host = "localhost";
$user = "root";
$password = "";
$database = "php-admin-panel";

$conn = new mysqli($host, $user, $password, $database);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
?>
  • Variables are set to store the database connection details: $host (server hostname), $user (MySQL username), $password (password for the user), and $database (name of the database).
  • The mysqli object, named $conn, is created to connect to the database using the provided credentials.
  • It checks if there’s a connection error with $conn->connect_error.
  • If there is a connection error, it terminates the script and displays an error message including the connection error details.

Suggestion

This is a simplified overview of setting up a PHP admin panel. The complexity of your admin panel can vary based on your specific requirements and the features you want to implement.

You have set up a  basic configuration. now, follow the next step to create an admin login

Next Steps – PHP Admin Panel Login