Jun 9, 2018

Atom - Elegant Text Editor

Atom

If you are looking for a text editor software that has interesting look and features, then you should try this text editor. Atom is a free and open-source text and source code editor for macOS, Linux, and Microsoft Windows with support for plug-ins written in Node.js, and embedded Git Control, developed by GitHub. With their slogan "A hackable text editor for the 21st Century", the atom will provide different atmosphere and comfort as long as you do the coding process. All will look fun and without you realize the coffee in the glass has run out ^_^.

Some features of this text editor are:
  1. Directly connected with github.
  2. Have many themes.
  3. Install Packages Easily
  4. Customize Styling
Atom
    Download Atom

    Get latest version of Atom

    Read More

    Apr 7, 2018

    MySQL Data Counting with PHP Script

    MySQL Data Counting with PHP Script

    MySQL Data Counting with PHP Script. In this tutorial, we will calculate the data in a database. Some calculation process used is to find the number of values in a field or count the number of rows from the query result. To run this process, also used some functions that is MySQL COUNT() and SUM().

    1. Create Database
    Create a new database for example abc_database . You can create it using phpMyAdmin, SQLyog, or similar applications.
    MySQL Table Data Counting with PHP Script

    Then create a table users and orders with columns like the picture below and fill the table data. status_order field in the orders table is filled with the numbers 0 or 1. 0 it means new orders and 1 are the complete orders
    MySQL Table Data Counting with PHP Script

    MySQL Table Data Counting with PHP Script

    MySQL Table Data Counting with PHP Script

    MySQL Table Data Counting with PHP Script

    Or you can use other options to create this database with import sql file. sql databse file can be downloaded in this LINK.

    2. View data with PHP-HTML Code (index.php)
    You can create this page with standart html code or you can use the Bootstrap Admin Template. The main part in this file is contained in the php script used for the database connection and the process to calculate the data.
    connection to database
    <?php
    session_start();
    // db connection-----------------------------
    mysql_connect('localhost', 'root', '');//'hostname','username','password'
    mysql_select_db('abc_database');
    
    ?>
    

    count new users
    <div class="mr-5">
     <?php
     $sql = "SELECT count(*) AS data1 FROM users";
     $query = mysql_query($sql);
     $result = mysql_fetch_array($query);
     echo $result['data1'];
     ?> Total Users
    </div>
    

    calculate the amount of revenue from the complete order (status_order=1)
    <div class="mr-5">
     <?php
     $sql = "SELECT SUM(total_price) AS data2 FROM orders WHERE status_order=1";
     $query = mysql_query($sql);
     $result = mysql_fetch_array($query);
     echo $result['data2'];
     ?> USD Earnings
    </div>
    

    count new orders (status_order=0)
    <div class="mr-5">
     <?php
     $sql = "SELECT count(*) AS data3 FROM orders WHERE status_order=0";
     $query = mysql_query($sql);
     $result = mysql_fetch_array($query);
     echo $result['data3'];
     ?> New Orders!
    </div>
    

    count complete orders (status_order=1)
    <div class="mr-5">
     <?php
     $sql = "SELECT count(*) AS data4 FROM orders WHERE status_order=1";
     $query = mysql_query($sql);
     $result = mysql_fetch_array($query);
     echo $result['data4'];
     ?> Complete!
    </div>
    

    Complete Script (index.php)
    <?php
    session_start();
    // db connection-----------------------------
    mysql_connect('localhost', 'root', '');//'hostname','username','password'
    mysql_select_db('abc_database');
    
    ?>
    
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      <meta name="description" content="">
      <meta name="author" content="">
      <title>SB Admin - Start Bootstrap Template</title>
      <!-- Bootstrap core CSS-->
      <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <!-- Custom fonts for this template-->
      <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
      <!-- Page level plugin CSS-->
      <link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
      <!-- Custom styles for this template-->
      <link href="css/sb-admin.css" rel="stylesheet">
    </head>
    
    <body class="fixed-nav sticky-footer bg-dark" id="page-top">
      <!-- Navigation-->
      <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top" id="mainNav">
        <a class="navbar-brand" href="index.html">Cheese Store</a>
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarResponsive">
          <ul class="navbar-nav navbar-sidenav" id="exampleAccordion">
            <li class="nav-item" data-toggle="tooltip" data-placement="right" title="Dashboard">
              <a class="nav-link" href="index.html">
                <i class="fa fa-fw fa-dashboard"></i>
                <span class="nav-link-text">Dashboard</span>
              </a>
            </li>
            <li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
              <a class="nav-link" href="charts.html">
                <i class="fa fa-fw fa-area-chart"></i>
                <span class="nav-link-text">Charts</span>
              </a>
            </li>
            <li class="nav-item" data-toggle="tooltip" data-placement="right" title="Tables">
              <a class="nav-link" href="tables.html">
                <i class="fa fa-fw fa-table"></i>
                <span class="nav-link-text">Tables</span>
              </a>
            </li>
            <li class="nav-item" data-toggle="tooltip" data-placement="right" title="Example Pages">
              <a class="nav-link nav-link-collapse collapsed" data-toggle="collapse" href="#collapseExamplePages" data-parent="#exampleAccordion">
                <i class="fa fa-fw fa-file"></i>
                <span class="nav-link-text">Example Pages</span>
              </a>
              <ul class="sidenav-second-level collapse" id="collapseExamplePages">
                <li>
                  <a href="#">Login Page</a>
                </li>
                <li>
                  <a href="#">Registration Page</a>
                </li>
                <li>
                  <a href="#">Forgot Password Page</a>
                </li>
              </ul>
            </li>
          </ul>
          <ul class="navbar-nav sidenav-toggler">
            <li class="nav-item">
              <a class="nav-link text-center" id="sidenavToggler">
                <i class="fa fa-fw fa-angle-left"></i>
              </a>
            </li>
          </ul>
          <ul class="navbar-nav ml-auto">
            <li class="nav-item">
              <form class="form-inline my-2 my-lg-0 mr-lg-2">
                <div class="input-group">
                  <input class="form-control" type="text" placeholder="Search for...">
                  <span class="input-group-append">
                    <button class="btn btn-primary" type="button">
                      <i class="fa fa-search"></i>
                    </button>
                  </span>
                </div>
              </form>
            </li>
            <li class="nav-item">
              <a class="nav-link" data-toggle="modal" data-target="#exampleModal">
                <i class="fa fa-fw fa-sign-out"></i>Logout</a>
            </li>
          </ul>
        </div>
      </nav>
      <div class="content-wrapper">
        <div class="container-fluid">
          <!-- Breadcrumbs-->
          <ol class="breadcrumb">
            <li class="breadcrumb-item">
              <a href="#">Dashboard</a>
            </li>
            <li class="breadcrumb-item active">My Dashboard</li>
          </ol>
          <!-- Icon Cards-->
          <div class="row">
            <div class="col-xl-3 col-sm-6 mb-3">
              <div class="card text-white bg-primary o-hidden h-100">
                <div class="card-body">
                  <div class="card-body-icon">
                    <i class="fa fa-fw fa-users"></i>
                  </div>
                  <div class="mr-5">
      <?php
      $sql = "SELECT count(*) AS data1 FROM users";
      $query = mysql_query($sql);
      $result = mysql_fetch_array($query);
      echo $result['data1'];
      ?> Total Users
           </div>
                </div>
                <a class="card-footer text-white clearfix small z-1" href="#">
                  <span class="float-left">View Details</span>
                  <span class="float-right">
                    <i class="fa fa-angle-right"></i>
                  </span>
                </a>
              </div>
            </div>
            <div class="col-xl-3 col-sm-6 mb-3">
              <div class="card text-white bg-warning o-hidden h-100">
                <div class="card-body">
                  <div class="card-body-icon">
                    <i class="fa fa-fw fa-dollar"></i>
                  </div>
                  <div class="mr-5">
      <?php
      $sql = "SELECT SUM(total_price) AS data2 FROM orders WHERE status_order=1";
      $query = mysql_query($sql);
      $result = mysql_fetch_array($query);
      echo $result['data2'];
      ?> USD Earnings
           </div>
                </div>
                <a class="card-footer text-white clearfix small z-1" href="#">
                  <span class="float-left">View Details</span>
                  <span class="float-right">
                    <i class="fa fa-angle-right"></i>
                  </span>
                </a>
              </div>
            </div>
            <div class="col-xl-3 col-sm-6 mb-3">
              <div class="card text-white bg-success o-hidden h-100">
                <div class="card-body">
                  <div class="card-body-icon">
                    <i class="fa fa-fw fa-shopping-cart"></i>
                  </div>
                  <div class="mr-5">
      <?php
      $sql = "SELECT count(*) AS data3 FROM orders WHERE status_order=0";
      $query = mysql_query($sql);
      $result = mysql_fetch_array($query);
      echo $result['data3'];
      ?> New Orders!
           </div>
                </div>
                <a class="card-footer text-white clearfix small z-1" href="#">
                  <span class="float-left">View Details</span>
                  <span class="float-right">
                    <i class="fa fa-angle-right"></i>
                  </span>
                </a>
              </div>
            </div>
            <div class="col-xl-3 col-sm-6 mb-3">
              <div class="card text-white bg-danger o-hidden h-100">
                <div class="card-body">
                  <div class="card-body-icon">
                    <i class="fa fa-fw fa-check"></i>
                  </div>
                  <div class="mr-5">
      <?php
      $sql = "SELECT count(*) AS data4 FROM orders WHERE status_order=1";
      $query = mysql_query($sql);
      $result = mysql_fetch_array($query);
      echo $result['data4'];
      ?> Complete!
           </div>
                </div>
                <a class="card-footer text-white clearfix small z-1" href="#">
                  <span class="float-left">View Details</span>
                  <span class="float-right">
                    <i class="fa fa-angle-right"></i>
                  </span>
                </a>
              </div>
            </div>
          </div>
          <!-- Area Chart Example-->
          <div class="card mb-3">
            <div class="card-header">
              <i class="fa fa-area-chart"></i> Area Chart Example</div>
            <div class="card-body">
              <canvas id="myAreaChart" width="100%" height="30"></canvas>
            </div>
            <div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>
          </div>
        </div>
        <!-- /.container-fluid-->
        <!-- /.content-wrapper-->
        <footer class="sticky-footer">
          <div class="container">
            <div class="text-center">
              <small>Copyright © Your Website 2018</small>
            </div>
          </div>
        </footer>
        <!-- Scroll to Top Button-->
        <a class="scroll-to-top rounded" href="#page-top">
          <i class="fa fa-angle-up"></i>
        </a>
        <!-- Logout Modal-->
        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">×</span>
                </button>
              </div>
              <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
              <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                <a class="btn btn-primary" href="login.html">Logout</a>
              </div>
            </div>
          </div>
        </div>
        <!-- Bootstrap core JavaScript-->
        <script src="vendor/jquery/jquery.min.js"></script>
        <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
        <!-- Core plugin JavaScript-->
        <script src="vendor/jquery-easing/jquery.easing.min.js"></script>
        <!-- Page level plugin JavaScript-->
        <script src="vendor/chart.js/Chart.min.js"></script>
        <script src="vendor/datatables/jquery.dataTables.js"></script>
        <script src="vendor/datatables/dataTables.bootstrap4.js"></script>
        <!-- Custom scripts for all pages-->
        <script src="js/sb-admin.min.js"></script>
        <!-- Custom scripts for this page-->
        <script src="js/sb-admin-datatables.min.js"></script>
        <script src="js/sb-admin-charts.min.js"></script>
      </div>
    </body>
    
    </html>
    

    MySQL Table Data Counting with PHP Script

    Okay.., That's all for the tutorial MySQL Table Data Counting with PHP Script, complete code (and file) can be downloaded at the download link bellow. Hope you like it and Enjoy...


    Read More

    Bootrstrap 4 Login with MySQL Database

    Bootrstrap 4 Login with MySQL Database

    Bootrstrap 4 Login with MySQL Database. In this tutorial we will create login system using database and bootstrap 4 frame work. So follow the steps well and Happy coding!!

    1. Create Database
    Create a new database for example abc_database . You can create it using phpMyAdmin, SQLyog, or similar applications.
    Bootrstrap 4 Login with MySQL Database

    Then create a table users with columns like the picture below and fill with login data. Important !! for password is using md5 algorithm, so make sure your password has been converted in md5 format.
    You can make the conversion through the  http://www.miraclesalad.com/webtools/md5.php
    Bootrstrap Login with MySQL Database

    Bootrstrap 4 Login with MySQL Database

    In addition to the above steps, the process of creating tables can use the import sql that has been included in the download file. in this file, I have input some data for login process:
    username: admin, password: admin;
    username: member, password: member; 

    2. Create Application
    Login Page (index.php) created using template you can get at https://startbootstrap.com/template-overviews/coming-soon/
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
    
        <title>ABC Corp</title>
     <link rel="icon" type="image/png" href="img/favicon.ico"/>
        <!-- Bootstrap core CSS -->
        <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    
        <!-- Custom fonts for this template -->
        <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Merriweather:300,300i,400,400i,700,700i,900,900i" rel="stylesheet">
        <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    
        <!-- Custom styles for this template -->
        <link href="css/coming-soon.min.css" rel="stylesheet">
      </head>
      <body>
        <div class="overlay"></div>
        <div class="masthead">
          <div class="masthead-bg"></div>
          <div class="container h-100">
            <div class="row h-100">
              <div class="col-12 my-auto">
                <div class="masthead-content text-white py-5 py-md-0">
                  <h1 class="mb-3"><i class="fa fa-adn"></i> ABC Corp</h1>
      <form method='post' action="login-process.php">
      <div class="input-group input-group-newsletter" style="padding:10px 0;">
      <input type="text" name="username" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon" required autofocus>
      </div>
      <div class="input-group input-group-newsletter" style="padding:10px 0;">
      <input type="password" name="password" class="form-control" placeholder="Password" aria-label="Username" aria-describedby="basic-addon" required autofocus>
      </div>
      <div class="input-group input-group-newsletter" style="padding:10px 0;">
      <button class="btn btn-secondary" type="submit" name="login">Login</button> 
      </div>
      </form>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="social-icons">
          <ul class="list-unstyled text-center mb-0">
            <li class="list-unstyled-item">
              <a href="#">
                <i class="fa fa-twitter"></i>
              </a>
            </li>
            <li class="list-unstyled-item">
              <a href="#">
                <i class="fa fa-facebook"></i>
              </a>
            </li>
            <li class="list-unstyled-item">
              <a href="#">
                <i class="fa fa-instagram"></i>
              </a>
            </li>
          </ul>
        </div>
        <!-- Bootstrap core JavaScript -->
        <script src="vendor/jquery/jquery.min.js"></script>
        <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
        <!-- Plugin JavaScript -->
        <script src="vendor/vide/jquery.vide.min.js"></script>
        <!-- Custom scripts for this template -->
        <script src="js/coming-soon.min.js"></script>
      </body>
    </html>
    

    Bootrstrap 4 Login with MySQL Database

    Login Check (login-process.php) 
    This file used to continue the process after the login button is pressed. username and password data that has been entered in the login page will be checked on the database. If data is valid it will be directed to the main page (main_pages folder). when the data is invalid then the process will be redirected back to the login page.
    <?php
    session_start();
    // db config -------------------------------------------------
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "abc_database";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    //----------------------------------------------------------
    if ( isset($_POST['login'])){
        $username = $_POST['username'];
     $password = md5( $_POST['password']);
    
        $sql_query = "SELECT name, email, username, id FROM users 
                      WHERE username='$username' AND password='$password'
                      LIMIT 1"; //sql query
        $result = $conn->query($sql_query);
        if ($result->num_rows > 0) {
        // data valid
           while($row = $result->fetch_assoc()) {
            //retrieve data from database and stored in session;
            $_SESSION['name']= $row["name"]; 
     $conn->close();
     header('location:main_pages/index.php');//dirrect to main page folder
     exit();
     }
         } else { //data invalid
     //alert then back to login page
     echo "<script language=\"javascript\">alert(\"Invalid username or password\");
     document.location.href='index.php?error_login';</script>";
     exit();
         }
    } else {
        header('location:index.php');
        exit();
    }
    ?>
    

    Main Page (index.php)
    This file is the main page that can be accessed when the login is successful. This file is located inside a different folder (in the example: main_pages folder).
    <?php 
    session_start();
    if ( !isset($_SESSION['name'])){// handling if dont'have session
    
     header('location:../index.php'); 
     exit();
    } 
    $name = $_SESSION['name'];
    ?>
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="">
        <title>ABC Corp</title>
     <link rel="icon" type="image/png" href="../img/favicon.ico"/>
        <!-- Bootstrap core CSS -->
        <link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
        <!-- Custom fonts for this template -->
        <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Merriweather:300,300i,400,400i,700,700i,900,900i" rel="stylesheet">
        <link href="../vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
        <!-- Custom styles for this template -->
        <link href="../css/coming-soon.min.css" rel="stylesheet">
      </head>
      <body>
        <div class="overlay"></div>
        <div class="masthead">
          <div class="masthead-bg"></div>
          <div class="container h-100">
            <div class="row h-100">
              <div class="col-12 my-auto">
                <div class="masthead-content text-white py-5 py-md-0">
                  <img src="../img/profile-icon.png" class="rounded-circle" width="240px" height="240px" style="padding:20px;">
      <h2 class="mb-3"><?php echo $name; ?></h2>
      <p class="mb-5">Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
      In eros leo, fermentum a pellentesque non, sollicitudin a ipsum.
      <strong>Pellentesque venenatis </strong> nunc vestibulum, laoreet ipsum ac, ultricies mauris.</p>
      <div class="input-group input-group-newsletter" style="padding:10px 0;">
      <a href="logout.php" class="btn btn-secondary">Logout</a> 
      </div>
                </div>
              </div>
            </div>
          </div>
        </div>
    
        <div class="social-icons">
          <ul class="list-unstyled text-center mb-0">
            <li class="list-unstyled-item">
              <a href="#">
                <i class="fa fa-twitter"></i>
              </a>
            </li>
            <li class="list-unstyled-item">
              <a href="#">
                <i class="fa fa-facebook"></i>
              </a>
            </li>
            <li class="list-unstyled-item">
              <a href="#">
                <i class="fa fa-instagram"></i>
              </a>
            </li>
          </ul>
        </div>
    
        <!-- Bootstrap core JavaScript -->
        <script src="../vendor/jquery/jquery.min.js"></script>
        <script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    
        <!-- Plugin JavaScript -->
        <script src="../vendor/vide/jquery.vide.min.js"></script>
    
        <!-- Custom scripts for this template -->
        <script src="../js/coming-soon.min.js"></script>
    
      </body>
    
    </html>
    

    PHP Login with MySQL Database

    Logout Process (logout.php)
    When logout button is pressed, the process will be directed to this file. Function of this file is to delete a session that has been successfully logged. After that the process will be directed to the login page. 
    <?php
    session_start();
    session_destroy();
    header('location:../index.php');//goto login page
    ?>
    
    Okay.., That's all for the tutorial create Login form with Bootstrap 4 , for a more complete code (and file) can be downloaded at the download link. hope you like it and Enjoy Coding .
    Read More