PHP and MySQL Sign Up/Login System

Oct 12, 2024

Complete Sign Up and Login System Using PHP and MySQL

Overview

  • Learn to create a complete sign up and login system.
  • Use PHP and MySQL database.
  • Demo includes registration and login forms with validation.

Software Required

  • Download and install XAMPP for local server.
  • Locate installation directory (e.g., C:\xampp).

Project Structure

  • Place all project files in the htdocs folder of XAMPP.
  • Create a new project folder named login_register.

Coding Part

Registration Form

  1. Create a file: registration.php.
  2. HTML5 Boilerplate Code
    • Use Visual Studio Code to add boilerplate.
    • Add a title: "Registration Form".
  3. Form Structure:
    • Form Method: POST.
    • Form Action: same file (registration.php).
    • Form Fields:
      • Full Name (Text field).
      • Email (Type: email).
      • Password (Type: password).
      • Repeat Password (Type: password).
      • Submit Button (Type: submit).
  4. Styling:
    • Utilize Bootstrap for quick styling.
    • Add custom styles in style.css (max-width, padding, margin, etc.).

MySQL Database Setup

  1. Access phpMyAdmin via: localhost/phpmyadmin.
  2. Create Database: name it login_register.
  3. Create Table: name it users with columns:
    • ID (INT, Auto Increment).
    • Full Name (VARCHAR, 128).
    • Email (VARCHAR, 255).
    • Password (VARCHAR, 255).

PHP Code for Processing Registration

  • Insert code to handle form submission and validation:
  1. Check if the form is submitted.
  2. Validate input fields (check for empty values, valid email format, password length).
  3. Encrypt password using password_hash() before inserting into database.
  4. Insert values into the database after validation.
  5. Display success or error messages based on the result.

Login Form

  1. Create a file: login.php.
  2. HTML5 Boilerplate Code
    • Include the same styles as the registration form.
  3. Form Structure:
    • Fields for Email and Password.
    • Submit Button (Type: submit).
  4. PHP Code for Processing Login
    • Validate user credentials against the database.
    • Use password_verify() to check password.
    • Redirect to a dashboard if successful.

User Dashboard

  1. Create a file: index.php.
    • Add a welcome message.
  2. Session Management:
    • Start session to keep track of logged-in users.
    • Redirect users based on their login status.

Logout Functionality

  1. Create a file: logout.php.
    • Start session and destroy session.
    • Redirect to login page.

Navigation Links

  • Add links between login and registration forms for user convenience.

Conclusion

  • Successfully created a PHP and MySQL based sign up and login system.
  • Implemented validation and session management for user security.
  • Thanks for watching! Don't forget to subscribe.