Login/Users Noob Version - The Noob CMS

Login/Users Noob Version - The Noob CMS

Lets create an Empty Folder in your Web Server and create the following files;

noobcms

In PHPMyAdmin or MySQL Workbench Create the Following Database Structure and our database name is noob_db_

Our Config File Should Look like this

config.php

<?php
    //CREATE SESSTION
    session_start();

//TIMEZONE
date_default_timezone_set('Asia/Karachi');

//SITE PATH
define('SITE', 'http://localhost/noobcms/');

//DATABASE CREDENTIALS
define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', '');
define('DBNAME', 'noob_db');

//CREATE CONNECTION
$conn = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME);

//CHECK CONNECTION
if (!$conn) {
    die("Connection failed: ".mysqli_connect_error());
}

?>

admin_users.php

<?php
    include("../includes/config.php");

if (isset($_POST['btnCreateUser'])) {
    $email  = $_POST['email'];
    $pass   = $_POST['pass'];
    $name   = $_POST['name'];

    $sql = "SELECT * FROM users WHERE email = '$email'";
    if ($result = $conn-&gt;query($sql)) {
        if ($result-&gt;num_rows == 0) {
            //Email Address Doesnt Exists
            //Add User to Database
            $pass   = md5($pass); //We are Encrypting Password with MD5 Hash
            $addSQL = "INSERT INTO users (email, password, name) VALUES ('$email', '$pass', '$name')";
            $conn-&gt;query($addSQL);

            echo "New User Added";
        } else {
            //Email Address Already Exists
            echo "Email Address Already Exists";
        }
    }
}

?> <head> <meta charset="UTF-8"> <title>Admin: Users</title> </head>

&lt;body&gt;
    &lt;div&gt;
        &lt;form action="" method="POST"&gt;
            &lt;label&gt;Email Address&lt;/label&gt;
            &lt;input name="email" type="text" placeholder="Enter Email Address..." /&gt;

            &lt;label&gt;Password&lt;/label&gt;
            &lt;input name="pass" type="password" placeholder="Password..." /&gt;

            &lt;label&gt;Full Name&lt;/label&gt;
            &lt;input name="name" type="text" placeholder="Full Name..." /&gt;

            &lt;button name="btnCreateUser"&gt;Create User&lt;/button&gt;
        &lt;/form&gt;
    &lt;/div&gt;

    &lt;div&gt;
        &lt;table border="1"&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                    &lt;th&gt;Email&lt;/th&gt;
                    &lt;th&gt;Name&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
                &lt;?php
                    $userResult = $conn-&gt;query('SELECT * FROM users');
                    if ($userResult-&gt;num_rows != 0) {
                        while ($row = $userResult-&gt;fetch_array()) {
                            ?&gt;
                            &lt;tr&gt;
                                &lt;td&gt;&lt;?php echo $row["email"];?&gt;&lt;/td&gt;
                                &lt;td&gt;&lt;?php echo $row["name"];?&gt;&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;?php
                        }
                    }
                ?&gt;
            &lt;/tbody&gt;
        &lt;/table&gt;
    &lt;/div&gt;
&lt;/body&gt;

Now if you run this file in the browser

login.php

<?php
    include("includes/config.php");

if (isset($_POST['btnLogin'])) {
    $email  = $_POST['email'];
    $pass   = md5($_POST['pass']);

    $sql = "SELECT * FROM users WHERE email = '$email' AND password = '$pass'";
    if ($result = $conn-&gt;query($sql)) {
        if ($result-&gt;num_rows == 1) {
            echo "Login Successful";
        } else {
            echo "Invalid Credentials";
        }
    }
}

?>

&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;Login&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;div&gt;
        &lt;form action="" method="POST"&gt;
            &lt;label&gt;Email Address&lt;/label&gt;
            &lt;input name="email" type="text" placeholder="Enter Email Address..." /&gt;

            &lt;label&gt;Password&lt;/label&gt;
            &lt;input name="pass" type="password" placeholder="Password..." /&gt;

            &lt;button name="btnLogin"&gt;Login&lt;/button&gt;
        &lt;/form&gt;            
    &lt;/div&gt;
&lt;/body&gt;

Thanks For Visiting, Keep Visiting

☞ PHP with Laravel for beginners - Become a Master in Laravel

☞ Laravel PHP Framework Tutorial - Full Course for Beginners (2019)

How to Preventing free-range Wordpress hooks

php web-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

PHP Web Application Development Company

As a top **PHP Web Application Development Company in USA**[https://www.dataeximit.com/php-development-services/](https://www.dataeximit.com/php-development-services/ "https://www.dataeximit.com/php-development-services/"), we at Data EximIT have...

PHP Website Development

Skenix Infotech is a leading PHP Web Development Company that helps companies get results with industry best practices. Get affordable PHP Development Services.

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

Advantages of Hiring PHP Developer for your Website Project

PHP - Hypertext pre-processor, a scripting language used by many people in developing web pages, but most of us are unaware even of the full form. To train someone and make them learn this whole language is as difficult and time-consuming as it is...

Hire PHP Developer and Web Developer for your Online Business

PHP is widely used open-source scripting language it helps in making dynamically easy your websites and web application. Mobiweb Technology is your best technical partner and offering you solution for any kind of website and application...