PHP Friend Request System

Here I will share with you a PHP Project which is Friend Request System like facebook.

Features of this Friend Request System:

Steps to Setup this Project

1. Create Database and its Tables

After creating the database, use the following SQL to create its tables (users, friend_requests, friends).

If you are using phpMyAdmin:

  1. Go to the SQL tab after selecting the frnd_req_system.
  2. Paste the follwing sql code into the textarea and click on the Go button to excute this code.
  3. After executing the code, you will see that the tables are created and ready to use.

creating tables for frnd_req_system in phpmyadmin

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";

CREATE TABLE `friends` (
  `user_one` int(11) NOT NULL,
  `user_two` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

CREATE TABLE `friend_requests` (
  `sender` int(11) NOT NULL,
  `receiver` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `name` varchar(30) NOT NULL,
  `email` varchar(50) NOT NULL,
  `password` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


ALTER TABLE `friends`
  ADD KEY `user_one` (`user_one`),
  ADD KEY `user_two` (`user_two`);

ALTER TABLE `friend_requests`
  ADD KEY `sender` (`sender`),
  ADD KEY `receiver` (`receiver`);

ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `email` (`email`);


ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `friends`
  ADD CONSTRAINT `friends_ibfk_1` FOREIGN KEY (`user_one`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `friends_ibfk_2` FOREIGN KEY (`user_two`) REFERENCES `users` (`id`) ON DELETE CASCADE;

ALTER TABLE `friend_requests`
  ADD CONSTRAINT `friend_requests_ibfk_1` FOREIGN KEY (`sender`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `friend_requests_ibfk_2` FOREIGN KEY (`receiver`) REFERENCES `users` (`id`) ON DELETE CASCADE;
COMMIT;

Alternative database structure:

You can also do the following where you will have only one table to handle the requests –


2. Graphical Explanation of the Working of this System

Graphical Explanation of Working of php friend request system


3. Setup the Project Folder:

Go in the root directory of your localhost which is htdocs or www, and then create a folder called php-friend-request-system (you can give any name), this is our project folder.

htdocs/
└── php-friend-request-system/

Here is the structure of this folder:

PHP Friend request system folder structure

4. Download the Project:

Now download or clone the chandantudu/php-friend-request-system repo into the project folder or you can extract the downloaded zip file here.

5. Test the application:

http://localhost/php-friend-request-system/register.php
http://localhost/php-friend-request-system/login.php

Some Screenshots of this application:

login page


Profile page


Notifications page