How To Submit Username And Password In HTML And PHP- letsbug

     Today we are creating a small project that many of you might have come across. This is a basic username and password submission project in PHP. Which is often in colleges. In this project we are going to ask the user to enter a username and a password.

    We will have a frontend page in html and a Xampp PHP server. When the user clicks on submit button we send the username and password to the server. Where it will be validated against our conditions.

    If the username and password is correct then we will display the user "you are logged in" else will display "invalid".  so let's get started.

Prerequisite: 
  1. Basic
    1. HTML
    2. CSS
    3. JAVASCRIPT
  2. PHP CONCEPTS 
    1.  Basics only.

Submit Username and Password In HTML and PHP

    Our project folder will look like this. 
    
    -userNamePassword 
            - server
                    - index.php
            - index.html

code: index.php
<?php

    $username = isset($_POST['username']) ? $_POST['username'] : '';
    $password = isset($_POST['password']) ? $_POST['password'] : '';
    $submitBtn = isset($_POST['submitBtn']);

    $realUsername = 'admin';
    $realPassword = 'admin';

    if (isset($submitBtn)) {
        if ($username == '' || $password == '') {
            echo '<p>Please enter a username and password</p>';
        } else {
            if ($username == $realUsername && $password == $realPassword) {
                echo '<p>You are logged in!</p>';
            } else {
                echo '<p>Incorrect username or password</p>';
            }
        }
    }

?>
code:index.html
<!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.0">
    <title>User Name Password Submission</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background-color: #f5f5f5;
            width: 100vw;
            height: 70vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }

        .container {
            padding: 2rem;
            border: 1px solid #ccc;
            background-color: #fff;
            box-shadow: 0 0 20px #ccc;
            border-radius: 5px;
        }

        .container h1 {
            font-size: 2em;
            margin-top: 0;
            margin-bottom: 0;
            font-weight: lighter;
        }

        .container form {
            margin-top: 20px;
        }

        .input input {
            width: 100%;
            padding: 12px 20px;
            margin: 8px 0;
            display: inline-block;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        .input label {
            font-size: 1.2em;
            font-weight: lighter;
            color: #333;
        }

        button {
            width: 100%;
            padding: 12px 20px;
            margin: 8px 0;
            display: inline-block;
            border: 1px solid #ccc;
            border-radius: 4px;
            background-color: #f5f5f5;
        }
    </style>

</head>

<body>
    <section class="container">
        <h1>User Name Password Submission</h1>
        <form action="./server/index.php" method="post">
            <div class="input">
                <label for="username">Username:</label>
                <input type="text" name="username" id="username" placeholder="Enter your username">
            </div>
            <div class="input">
                <label for="password">Password:</label>
                <input type="password" name="password" id="password" placeholder="Enter your password">
            </div>
            <button type="submit" name="submitBtn">Submit</button>
        </form>
    </section>
</body>

</html>
output: 

    
Username And Password Submission In PHP - letsbug
Frontend HTML page

Username And Password Submission In PHP - letsbug
When username and password is incorrect

Username And Password Submission In PHP - letsbug
When username and password is correct

You can following on github my github username is Aniket-git-hub

Comments

Categories

Big Data Analytics Binary Search Binary Search Tree Binary To Decimal binary tree Breadth First Search Bubble sort C Programming c++ Chemical Reaction and equation class 10 class 10th Class 9 Climate Complex Numbers computer network counting sort CSS Cyber Offenses Cyber Security Cyberstalking Data Science Data Structures Decimal To Binary Development diamond pattern Digital Marketing dust of snow Economics Economics Lesson 4 Email Validation English fire and ice Food Security in India Footprints Without feet Forest And Wildlife Resources game Geography Geography lesson 6 glassmorphism Glossary Graph HackerRank Solution hindi HTML image previewer India-Size And Location Insertion Sort Internet Network Status Interview Questions Introduction to cyber crime and cyber security IT javascript tricks json to CSV converter lesson 2 lesson 1 lesson 2 Lesson 3 Lesson 6 lesson 7 Life lines of National Economy life processes Linear Search Linked List lowest common ancestor Machine Learning MCQs median in array Merge sort min and max of two numbers Moment Money and Credit My Childhood Natural Vegetation and Wildlife NCERT Network connectivity devices Network Models Network Security No Men Are foreign Node.js operator overloading P5.js PHP Physical features of India Population Prime Numbers python Quick sort R language Rain on the roof Regular Expression Resources and development reversing array saakhi science Searching Algorithm Selection sort Social Media Marketing social science Software Engineering Software Testing Sorting Algorithm Stacks staircase pattern System Concepts Text Recognition The last Leaf time converter Time Passed From A Date Todo List App Tree Trending Technologies Understanding Economic Development username and password video player Visualization water resources Wired And Wireless LAN साखी
Show more

Popular Posts

Big Data MCQs(multiple choice questions) with answers - letsbug

Digital Marketing MCQ(Multiple Choice Questions) with Answers | part 1 | letsbug

Software Engineering MCQs questions with answers - letsbug