Video summary
Create Full Stack Login And Register Form With User & Admin Page Using HTML CSS PHP & MySQL Database
Main summary
Key takeaways
Summary of the video (technological concepts & features)
This tutorial walks through building a full-stack authentication system with:
- Frontend: HTML/CSS
- Backend: PHP + MySQL
It supports:
- Login
- Registration
- Two roles:
userandadmin - Role-based access control for separate pages
- Session-based authentication with logout
UI / Frontend (HTML + CSS + JS)
Login form (default view)
- Inputs: email, password
- Login button
- Link to show the registration form
Registration form (hidden by default)
- Inputs: name, email, password
- Role dropdown to select
useroradmin - Register button
- Link to return to the login form
Switching between forms
- Uses JavaScript via a
showForm(formID)function - Toggles the CSS class
activeon the login/register containers:- Registration form starts with
display: none - The active form changes to
display: block
- Registration form starts with
Styling
- Imports Google Fonts
- Uses Flexbox to center and lay out elements
- Adds styling for inputs/buttons, including hover effects
- Includes styling for error messages (pink background, dark red text)
Backend setup (PHP + MySQL)
Database creation (phpMyAdmin)
A database (e.g., usersDB) and a table (e.g., users) are created with 5 columns:
id(INT, primary key, auto-increment)name(VARCHAR(255))email(VARCHAR(255), UNIQUE)password(VARCHAR(255), stores hashed passwords)roll(ENUM:user,admin)
Key constraint: the email is unique, preventing duplicate registrations.
Configuration file: config.php
- Stores MySQL connection parameters (host/user/password/database name)
- Connects using
new mysqli(...) - Stops execution on connection error
Form submission flow (index.php + loginorregister.php)
index.php (main page)
- Uses sessions to remember:
- which form is active (
loginorregister) - error messages
- which form is active (
- Displays errors using helper functions:
showP(error)to render an error paragraphisActiveForm(formName, activeForm)to apply theactiveCSS class to the correct form
loginorregister.php (processor for both login & register)
The same endpoint processes both actions using:
isset($_POST['register'])isset($_POST['login'])
Registration logic
session_start()- Includes
config.php - Reads:
name,email,password,roll - Hashes password using:
password_hash(..., PASSWORD_DEFAULT) - Checks if the email already exists:
- If yes: sets a session error like “email is already registered” and keeps the user on the registration form
- If no: inserts the user into MySQL
- Redirects to
index.phpto show the login form
Login logic
- Looks up the user by email in MySQL
- If user exists:
- Validates password using
password_verify(enteredPassword, storedHash) - Stores session variables such as:
nameemail
- Redirects based on role:
- If
roll == admin→ redirect toadmin page.php - Otherwise → redirect to
user page.php
- If
- Validates password using
- If login fails:
- Sets session error “incorrect email or password”
- Keeps the login form active
- Redirects back to
index.php
Role-based protected pages (user/admin pages)
user page.php and admin page.php
Both pages enforce access control by:
session_start()- If the user is not logged in (session key missing), redirect to
index.php - If logged in:
- Display the user’s name from the session
- Include a logout button
The tutorial notes denying access when these pages are opened directly via URL without an active session.
Logout flow (logout.php)
A logout.php file:
- Starts the session (
session_start()) - Clears session variables using
session_unset() - Ends the session using
session_destroy() - Redirects back to
index.php
Tutorial result / demonstrated behavior
- Registering a user → redirects to login; correct login → user page
- Registering an admin → correct login → admin page
- Wrong email/password → shows “incorrect email or password”
- Trying to access admin/user pages directly without a session → redirected to login
Main speakers / sources
- Speaker/source: “codow” (YouTube channel: codow)