Cara membuat dashboard admin dengan php

PHP Bootstrap code implies making a bootstrapper that handles all the dynamic requests made to a server and apply the MVC system so that in future you can change the functionality for each unique application or component without changing the whole. Bootstrap help you to design websites faster and easier, includinging HTML and CSS based design templates.

PHP Bootstrap templates make it less complicated for clients to construct complex and compelling web apps. PHP requires a local server to run PHP code. Designers using Bootstrap with PHP can enjoy all these benefits.

Around 18 million websites were using the Bootstrap framework by the end of the year 2018. An increasing number of websites have begun utilizing the framework in 2019, and the numbers have been rising since then. In reality, Bootstrap has become the foremost loved choice of engineers when building compelling web applications.

A PHP dashboard is a single or multi-tab visualization tool that can be integrated within PHP projects. Usually, these are browser-based applications that are built as a customizable component of larger projects. A PHP dashboard is designed to accept raw data from other components of the projects and then present it in various formats. These dashboards are generally built using JS because of great (and smooth) integration between PHP and JavaScript.

That’s why in this tutorial, I will use Bootstrap for demonstrating the idea of PHP dashboards.

Prerequisites

For this tutorial, I assume that you have a PHP application installed on a web server. My setup is:

To make sure that that I don’t get distracted by server-level issues, I decided to host my application on the Cloudways PHP hosting platform because I get a highly optimized hosting stack and no server management hassles. You can try out Cloudways for free by signing for an account.

I will create a simple application for sales management. It contains a dashboard where the users can see the sales stats and maintain the data about the Products and add new Products. Users could also register for logging into the dashboard.

Cara membuat dashboard admin dengan php

Build Admin Dashboard UI

I have used the free Bootstrap 4 admin template available on GitHub. The template has a well-written code and all the right components for these tutorials. The template has a neat, elegant, and simple design. However, I intend to customize the template a little to make it unique to my application.

Create the Forms

The admin panel template comes with a full range of forms UI including registration and login.

For validation purposes, I simply use Html5 Validation and Custom PHP Validation.

Stop Wasting Time on Servers

Cloudways handle server management for you so you can focus on creating great apps and keeping your clients happy.

Registration Form

Forms for user registration is already available. I will just change the fields’ name and update the method and action:








 

 

 

 

 

 SB Admin - Start Bootstrap Template

 

 

 

 

 

 





 

   

     

Register an Account

     

                           

           

             

                                             

           

         

         

                                 

         

           

             

                                             

            

                                             

           

         

          Register                

         Login Page                

     

   

 

         

Here is what the registration form looks like after the above modifications:

Cara membuat dashboard admin dengan php

Login Form

Next, for the Login form, use the following code:








 

 

 

 

 

 SB Admin - Start Bootstrap Template

 

 

 

 

 

 





 

   

Login

     

                            

                                 

         

                                 

         

           

                         

         

         Login                

         Register an Account               

     

   

 

         

Here is how the login form looks like:

Cara membuat dashboard admin dengan php

Setting up the Database Connection

Since I am on Cloudways, I could easily access the MySQL database details in the Access Details tab:

Cara membuat dashboard admin dengan php

Create three tables in the database, users, products, sales_stats.

Use the following SQL queries to create the tables:

Users table

CREATE TABLE `users` (

`id` int(11) NOT NULL,

`username` varchar(100) NOT NULL,

`email` varchar(100) NOT NULL,

`password` varchar(100) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Products table

CREATE TABLE `products` (

`product_id` int(22) NOT NULL,

`product_name` varchar(22) NOT NULL,

`product_price` int(22) NOT NULL,

`product_cat` varchar(22) NOT NULL,

`product_details` varchar(22) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Sales table

CREATE TABLE `sales_stats` (

`id` int(22) NOT NULL,

`sales` int(22) NOT NULL,

`month` varchar(25) NOT NULL,

`pending_orders` int(55) NOT NULL,

`revenue` int(55) NOT NULL,

`Vistors` int(55) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Click the Database Manager on the Cloudways Platform and check the dbname and other credentials. Next, create the file server.php and paste the following code in it:

Registration

// REGISTER USER

if (isset($_POST['reg_user'])) {

// receive all input values from the form

$username = mysqli_real_escape_string($db, $_POST['username']);

$email = mysqli_real_escape_string($db, $_POST['email']);

$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);

$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);

// form validation: ensure that the form is correctly filled ...

// by adding (array_push()) corresponding error unto $errors array

if (empty($username)) { array_push($errors, "Username is required"); }

if (empty($email)) { array_push($errors, "Email is required"); }

if (empty($password_1)) { array_push($errors, "Password is required"); }

if ($password_1 != $password_2) {

array_push($errors, "The two passwords do not match");

}

// first check the database to make sure

// a user does not already exist with the same username and/or email

$user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";

$result = mysqli_query($db, $user_check_query);

$user = mysqli_fetch_assoc($result);

if ($user) { // if user exists

if ($user['username'] === $username) {

array_push($errors, "Username already exists");

}

if ($user['email'] === $email) {

array_push($errors, "email already exists");

}

}
ins
// Finally, register user if there are no errors in the form

if (count($errors) == 0) {

$password = md5($password_1);//encrypt the password before saving in the database

echo $password ;

$query = "INSERT INTO users(username, email, password)

VALUES('$username', '$email', '$password')";

mysqli_query($db, $query);

$_SESSION['username'] = $username;

$_SESSION['success'] = "You are now logged in";

header('location: login.php');

}

}

// ...

Login

// LOGIN USER

if (isset($_POST['login_user'])) {

$username = mysqli_real_escape_string($db, $_POST['username']);

$password = mysqli_real_escape_string($db, $_POST['password']);

if (empty($username)) {

array_push($errors, "Username is required");

}

if (empty($password)) {

array_push($errors, "Password is required");

}

if (count($errors) == 0) {

$password = md5($password);

$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";

$results = mysqli_query($db, $query);

if (mysqli_num_rows($results) == 1) {

$_SESSION['username'] = $username;

$_SESSION['success'] = "You are now logged in";

header('location: index.php');

}else {

array_push($errors, "Wrong username/password combination");

}

}

}?>

For Errors, create the new file with the name of errors.php and paste the following code in it:

 0) : ?>

Create the Product Page

Next, create the product.php page and paste the following code in it:


















SB Admin - Start Bootstrap Template





















Start Bootstrap













  1. Dashboard
  2. Product Page

Create Product

Submit

Copyright © Your Website 2018

Ready to Leave?
×

Insert Products in the Database

Next, I will create pserver.php file in the root folder and paste the following code in it:

connect_error) {

die("Connection failed: " . $conn->connect_error);

}

$sql = "INSERT INTO products (product_name,product_price,product_cat,product_details)

VALUES ('$pname', '$price', '$pcat','product_details')";

if ($conn->query($sql) === TRUE) {

echo "alert('New record created successfully')";

} else {

echo "Error: " . $sql . "
" . $conn->error; } } $conn->close(); ?>

Visualize the Data

I need to populate the Bootstrap datatable from the corresponding tables in the database. Connect the datatable to the database.

The following code can be used to populate the Bootstrap datatable. Let’s update the table code with the following code:








 

 

 

 

 

 SB Admin - Start Bootstrap Template

 

 

 

 

 

 





 

   

Login

     

                            

                                 

         

                                 

         

           

                         

         

         Login                

         Register an Account               

     

   

 

         
0

Here is how the table looks like after the above code:

Cara membuat dashboard admin dengan php

Next, I will use the data in the database and visualize it in the PHP admin dashboard in the form of line charts:

Cara membuat dashboard admin dengan php

As you can see, the top of the dashboard is occupied by four cards that display Monthly visitors, Revenue, New Orders, and New tickets. The data for these cards is derived from the database through a simple SELECT query.

Setup the Dashboard

Here is the complete code for the dashboard view that you need to put in index.php:








 

 

 

 

 

 SB Admin - Start Bootstrap Template

 

 

 

 

 

 





 

   

Login

     

                            

                                 

         

                                 

         

           

                         

         

         Login                

         Register an Account               

     

   

 

         
1

Conclusion

Now we have an application with Bootstrap 4 and PHP that you can use to add products into a database. All the data is maintained in the tables, and the most important data metrics are shown through cards at the top and the line charts. As you can see, the app is based on a PHP dashboard template that was customized to fit the requirements of the app design. You could also use a PHP admin template to create a more pleasing-looking admin for the app.

This application can also be implemented using an API where you don’t have to mix HTML and PHP code. The data will be added or retrieved from the database using the API.

Is bootstrap a CSS?

Bootstrap is an open-source CSS framework designed to coordinate with responsive, mobile, and front-end web development. It contains CSS- and JavaScript-based design for typography, forms, buttons, and other interface components.

Customer Review at

Cara membuat dashboard admin dengan php

“Cloudways hosting has one of the best customer service and hosting speed”

Sanjit C [Website Developer]

Pardeep Kumar

Pardeep is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. He love to work on Open source platform , Frameworks and working on new ideas. You can email him at [email protected]

Apa itu admin dashboard?

Dashbard Admin Dashboard adalah pusat control panel ber-platform yang berfungsi untuk mengatur semua kegiatan di sebuah situs atau Website.

Apa itu Dashboard dalam sebuah website?

Adapun masing-masing fitur dan fungsi menu pada halaman dashboard yaitu. Merupakan halaman depan website yang berisi informasi aktivitas terkini website dan akses cepat pembuatan posting baru. Halaman ini biasanya menampilkan.