Coursework COMP1841 Form
Coursework COMP1841 Form
Student ID : 001343181
Article Title : Student App to Study
Instructor : Huong Vu
Submission Date : 22/08/2024
Contents
I. Abstract...................................................................................................................................................... 4
II. Introduction .............................................................................................................................................. 4
III. Methodology ........................................................................................................................................... 4
Tools and Technologies............................................................................................................................. 4
Development Environment Setup ........................................................................................................... 5
IV. User Requirements .................................................................................................................................. 5
Requirements ........................................................................................................................................... 5
User Requirements ................................................................................................................................... 6
Use Case Diagram ..................................................................................................................................... 7
Actors: ....................................................................................................................................................... 7
Use Cases: ................................................................................................................................................. 7
V. Design ....................................................................................................................................................... 9
1. Database Schema Design ..................................................................................................................... 9
2. System Architecture Overview........................................................................................................... 10
2.1. Overview...................................................................................................................................... 10
2.2. Architecture Components ........................................................................................................... 10
2.3. Process Flow ................................................................................................................................ 11
2.4. Security Considerations............................................................................................................... 12
2.5. Scalability and Maintenance ....................................................................................................... 12
3. User Interface Design ......................................................................................................................... 12
Wireframes ......................................................................................................................................... 12
VI. Implementation .................................................................................................................................... 18
VII.Discussion about GDPR......................................................................................................................... 28
VIII. Testing ................................................................................................................................................. 30
IX. Challenges and Solution ........................................................................................................................ 31
Challenges............................................................................................................................................... 31
Results..................................................................................................................................................... 32
Discussion ............................................................................................................................................... 32
X. Conclusion .............................................................................................................................................. 33
Figure 1: Database Schema Design .............................................................................................................. 9
Figure 2: Login Page................................................................................................................................... 12
Figure 3: Home Page .................................................................................................................................. 13
Figure 4: Questions Page ............................................................................................................................ 14
Figure 5: Add Question Page ...................................................................................................................... 14
Figure 6: List Question Page....................................................................................................................... 15
Figure 7: Admin Area Page ......................................................................................................................... 16
Figure 8: Manager Users Page .................................................................................................................... 16
Figure 9: Manage Modules Page ................................................................................................................ 17
Figure 10: DatabaseConnection.php ........................................................................................................... 18
Figure 11: DatabaseFunction.php ............................................................................................................... 19
Figure 12: Questions.php ............................................................................................................................ 20
Figure 13: add_question.php ....................................................................................................................... 21
Figure 14: list_question.php........................................................................................................................ 22
Figure 15: delete_question.php ................................................................................................................... 23
Figure 16: edit_question.php ...................................................................................................................... 24
Figure 17: admin_area.php ......................................................................................................................... 25
Figure 18: manager_user.php ...................................................................................................................... 26
Figure 19: manage_modules.php ................................................................................................................ 27
Figure 20: login.php .................................................................................................................................... 28
I. Abstract
This project focuses on the development of "Greenwich Confession," a web-based student question-and-
answer system designed to facilitate efficient interaction between users. The application offers
functionalities for users to submit, manage, and view questions, with additional administrative tools for
managing system modules.
The system incorporates a user-friendly interface, developed using Tailwind CSS, to ensure a modern and
responsive design. Backend operations are handled through PHP and PDO, ensuring secure and efficient
database interactions. The project adheres to GDPR guidelines, prioritizing data protection and user
privacy. Comprehensive testing was conducted to verify the functionality and usability of the system,
confirming that all major features perform as intended.
II. Introduction
In this project, I will leverage the foundational skills and techniques acquired in lectures and labs to
develop a web-based PHP/MySQL CRUD system. Building upon the basic structure of an online joke
site, I will create a prototype system designed to facilitate peer-to-peer assistance among students through
a question-and-answer platform. This system, akin to a simplified and self-contained version of Stack
Overflow, will allow students to post, edit, and manage questions related to their coursework.
My task is to design and implement a system that not only provides a public-facing interface for viewing
and interacting with posts but also includes administrative functionalities for managing users, modules,
and communication with the system administrator. While the initial functionality will be limited, the
system is intended to be expandable in future iterations, offering a solid foundation for continued
development.
The following sections outline the essential features and requirements for the system, prioritizing the key
functionalities needed to meet the project's objectives.
III. Methodology
Tools and Technologies
In developing the web-based PHP/MySQL CRUD system, I utilized the following tools and technologies:
• Programming Languages: The core functionality of the system is implemented using PHP for
server-side scripting and HTML for the structure of the web pages. This combination allows for
dynamic content generation and interaction with users.
• Styling Framework: To enhance the visual appearance of the application, I employed Tailwind
CSS, a utility-first CSS framework. Tailwind allows for rapid and responsive design without the
need for extensive custom styles.
• Database Management System: The application utilizes MySQL as the database management
system, providing a robust platform for data storage and retrieval.
• Integrated Development Environment (IDE): For coding and development, I used Visual
Studio Code. This IDE offers a user-friendly interface and supports various extensions to
enhance productivity and coding efficiency.
• Local Server Environment: The development was conducted on a local server using XAMPP,
which provides an easy-to-use package that includes Apache, MySQL, and PHP, making it
suitable for testing the application locally.
Use Cases:
1. Login:
o Actor: Student, Admin
o Description: Authenticates users with their credentials and directs them to the
appropriate page based on their role.
2. Home Page Navigation:
o Actor: Student, Admin
o Description: Provides navigation options based on user role:
▪ Students: Navigate to the Questions Page.
▪ Admins: Navigate to both the Questions Page and Admin Area.
3. Questions Page:
o Add Question:
▪ Actor: Student
▪ Description: Allows Students to submit a new question, including details and an
optional image upload.
o List Questions:
▪ Actor: Student
▪ Description: Displays a list of all submitted questions with options to edit or
delete.
4. Admin Area:
o Manage Users:
▪ List Users:
▪ Actor: Admin
▪ Description: Displays a list of all users with options to view, edit, or
delete user accounts.
▪ Add User:
▪ Actor: Admin
▪ Description: Allows Admins to add, edit, or delete user accounts,
including optional profile images.
o Manage Modules:
▪ List Modules:
▪ Actor: Admin
▪ Description: Displays a list of all modules.
▪ Add/Edit Module:
▪ Actor: Admin
▪ Description: Allows Admins to add or edit module names and
descriptions.
5. Contact Form:
o Actor: Student
o Description: Enables Students to send messages to the system administrator.
Use Case Diagram Overview:
• Student interacts with:
o Login to access the system.
o Home Page Navigation to reach:
▪ Questions Page where they can Add Question and List Questions.
o Contact Form to send messages to the admin.
• Admin interacts with:
o Login to access the system.
o Home Page Navigation to reach:
▪ Questions Page (similar to Students).
▪ Admin Area where they can:
▪ Manage Users: List Users and Add User.
▪ Manage Modules: List Modules and Add/Edit Module.
V. Design
1. Database Schema Design
The database schema for the greenwich_confession system is designed to efficiently manage and
integrate key data elements. It includes four primary tables: modules, messages, users, and posts, each
serving distinct functions.
The modules table manages information about academic modules. It includes an id for unique
identification, module_name to specify the module's name, and description for additional details about the
module. This table ensures each module is uniquely identified and described, facilitating organization and
retrieval of module-related posts.
The messages table tracks communications between users and administrators. It contains an id for each
message, a user_id that links to the users table to identify the sender, the message content, and a
created_at timestamp to record when the message was sent. This table helps manage user feedback and
system queries efficiently.
The users table stores detailed information about individuals using the system. It includes an id for
unique identification, username and email which must be unique for each user, password for secure
authentication, and role to differentiate between 'admin' and 'student'. This table is crucial for managing
user accounts and their roles within the system.
The posts table handles the questions or posts submitted by students. It features an id for each post, a title,
content, and an optional image for visual support. The user_id links each post to its creator, and
module_id associates the post with a specific academic module. Timestamps for creation and updates
(created_at and updated_at) track the post’s lifecycle. This table is essential for managing user-generated
content and its association with modules.
In summary, this schema clearly defines the roles and relationships of each table, ensuring effective data
management and supporting the core functionalities of the greenwich_confession system.
2.1. Overview
The Greenwich Confession system is a web application designed for students to ask and manage
assignment-related queries. It provides functionalities for user authentication, question management, and
admin controls. The system is structured to include various components interacting through a well-
defined architecture.
o MySQL: Stores application data including users, posts, modules, and messages.
• Database Tables:
o Users: Manages user details such as username, email, and hashed passwords.
o Posts: Handles user queries, including title, content, associated images, and metadata.
o Modules: Contains information about different assignment modules.
o Messages: Stores messages related to posts and queries.
2.2.4. File Structure:
• /include: Contains essential PHP files for database connections and functions.
o DatabaseConnection.php: Provides a method to establish a connection to the MySQL
database.
o DatabaseFunction.php: Contains database-related functions like retrieving user details
and managing posts.
• /template: Holds HTML/PHP templates for rendering different pages.
o header.php: Includes the header section for all pages.
o footer.php: Includes the footer section for all pages.
o login.html.php: Template for the login page.
o manage_users.html.php: Template for the user management page.
• /public: Serves as the public-facing directory containing the entry points and public assets.
o login.php: Handles user login functionality and redirects based on authentication.
o manage_users.php: Displays the user management interface.
o add_question.php: Allows users to add new questions.
o list_question.php: Displays a list of questions.
My login page is a simple and intuitive interface that allows me to enter my username and password to
access the system. With the title "Greenwich Confession" prominently displayed at the top, the login form
is centered on the screen, featuring input fields for my username and password. I click the "Login" button
to submit my information and be redirected to the main page of the application. The page is designed with
a dark background and light text for clear readability, and it uses Tailwind CSS to ensure an attractive and
user-friendly design on both desktop and mobile devices.
The Home page is the landing page of my application, presenting a clear and inviting introduction. It
features a title "Greenwich Confession" and provides quick access to essential functionalities like adding
a question, viewing questions, and managing modules. The design uses a dark theme with elegant
typography and Tailwind CSS for a sleek, modern look. It ensures an easy navigation experience across
both desktop and mobile devices.
Figure 4: Questions Page
The Questions page displays a list of questions posted by users. Each entry includes a brief title that links
to detailed views. The page is designed to be clean and functional, allowing me to easily browse through
the questions and access further details. The layout is responsive and visually appealing, making use of
Tailwind CSS for styling.
The Add Question page allows me to submit a new question to the system. It includes fields for entering
the question title, selecting the user, choosing the module, and uploading an image if desired. Upon
submission, the page redirects me to the List Questions page, where I can view my newly added question.
The design is clean and functional, with Tailwind CSS providing a modern appearance.
The List Questions page provides an organized view of all questions submitted to the system. It displays
question titles in a list format with clickable links that direct me to detailed question views. This page
ensures a user-friendly experience by presenting information clearly and allowing easy navigation.
Tailwind CSS is used for consistent styling and responsiveness.
Figure 7: Admin Area Page
The Admin Area is a specialized section accessible only to administrators. It includes tools and
functionalities for managing users and modules within the system. The page layout is designed to provide
easy access to these management features, ensuring efficient administrative operations. The design is
consistent with the overall dark theme and uses Tailwind CSS for a polished look.
The Manager Modules page provides tools for managing the modules used within the system. It allows
me to view existing modules and add new ones. The design is straightforward and user-friendly, with
Tailwind CSS ensuring a consistent and visually appealing interface across devices.
VI. Implementation
The PHP code snippet provides a getDatabaseConnection() function to establish and return a connection
to a MySQL database using PDO. The function initializes the connection with parameters such as the
server (localhost), database name (greenwich_confession), username (root), and password (an empty
string). PDO is configured to handle errors by throwing exceptions, making it easier to detect and manage
connection issues. If an error occurs, the function terminates the script and displays an error message.
This function helps set up a flexible and secure database connection, supporting SQL operations in the
application.
Figure 11: DatabaseFunction.php
The PHP code defines several functions for managing database operations. addPost() inserts a new post
into the posts table, while getAllPosts() retrieves all posts with details from the posts, users, and
modules tables. deletePost() removes a post by its ID, and updatePost() updates post details.
getPostById() fetches a post by ID. addModule() adds a new module to the modules table, and
getAllModules() retrieves all modules. deleteModule() deletes a module by ID, while updateModule()
updates module details. getModuleById() gets a module by ID, and getPostsByModule() retrieves posts
related to a specific module. getUserById() and getAllUsers() fetch user details by ID and get all users,
respectively. requireLogin() redirects to the login page if the user is not logged in, and
getUserByUsername() retrieves user details by username.
Figure 12: Questions.php
The PHP code includes the DatabaseConnection.php file and sets the $admin_area variable to control
the visibility of the Admin Area link. It defines the $title variable as "Questions" and includes the
header.php file for the page header. The main content displays a section with options to view and add
questions, styled using Tailwind CSS. It concludes by including the footer.php file for the page footer.
Figure 13: add_question.php
The PHP code handles the process of adding a new question to the database. It starts by including the
DatabaseConnection.php file to establish a database connection. When a POST request is detected, it
collects form data, including the question title, content, user ID, and module ID. It also processes an
optional image upload by saving the file to the uploads directory.
The core functionality is to insert the new question into the posts table using a prepared SQL statement.
Upon successful insertion, the code redirects the user to list_question.php. If any errors occur during the
image upload or database insertion, an appropriate error message is displayed.
Figure 14: list_question.php
The PHP code is responsible for displaying a list of questions from the database. It includes the
DatabaseConnection.php file to establish a database connection and sets the page title to "List
Questions." The $admin_area flag is set to false, and the header.php template is included for consistent
page styling.
The code then attempts to fetch questions from the posts table using a PDO connection, ordering the
results by creation date. If successful, it displays each question in a styled list, showing the title, content,
asker, module, and optionally an image if available. If no questions are found, a message is displayed.
Finally, it includes the footer.php template for the page footer.
Figure 15: delete_question.php
The PHP code handles the deletion of a specific question. It starts by including the
DatabaseConnection.php and DatabaseFunction.php files to ensure necessary functions and database
connection are available.
The session is started, and the requireLogin() function is called to ensure the user is logged in. If a
question ID is provided via the GET request, the deleteQuestion($id) function is called to remove the
question from the database. After the deletion, the user is redirected to the list_question.php page.
Figure 16: edit_question.php
This PHP script is used to edit an existing question in the database. It includes necessary files for
database connection (include 'include/DatabaseConnection.php') and functionality (include
'include/DatabaseFunction.php'). The page title is set to "Edit Question" and the admin area flag is
enabled ($admin_area = true).
The script retrieves the details of a question based on an ID provided in the URL ($id =
isset($_GET['id']) ? (int)$_GET['id'] : 0) and displays them in an editable form. Upon form submission,
the script processes the input data, including optional image uploads. The question’s information is then
updated in the database ($stmt->execute([$title, $content, $imagePaths, $user, $module, $id])). After the
update, the user is redirected to the list of questions (header('Location: list_question.php')). The script
also populates dropdown menus with users and modules fetched from the database.
Figure 17: admin_area.php
This PHP script is used to display the Admin Area page. It includes the necessary file for database
connection (include 'include/DatabaseConnection.php') and sets the admin area flag to true
($admin_area = true), indicating that the admin-specific links should be visible.
The page title is set to "Admin Area" and the header template is included (include
'template/header.php'). The main content includes a grid layout with two sections: Manage Users and
Manage Modules. Each section has a link that directs to the respective management pages
(manage_users.php and manage_modules.php). Finally, the footer template is included (include
'template/footer.php') to complete the page.
Figure 18: manager_user.php
This PHP script handles user management functionality, specifically for deleting users. It begins by
including the database connection file (include 'include/DatabaseConnection.php').
If the script receives a POST request with the delete action ($_POST['delete']), it retrieves the user ID
to delete ($userIdToDelete) from the POST data, prepares a SQL delete statement to remove the user
from the users table, and executes this statement. After deletion, it redirects to the Manage Users page
(manage_users.php).
Next, the script fetches the list of users from the database with a SELECT query and stores the results in
$users. The admin area flag ($admin_area = true) is set to show admin-specific links. Finally, the script
includes the manage users template (include 'template/manage_users.html.php') to display the user
management interface.
Figure 19: manage_modules.php
This PHP script manages module deletions. It begins by including the database connection file (include
'include/DatabaseConnection.php').
If a POST request with the delete action ($_POST['delete']) is received, it retrieves the module ID to
delete ($moduleIdToDelete) from the POST data, prepares a SQL delete statement to remove the module
from the modules table, and executes this statement. After deletion, it redirects to the Manage Modules
page (manage_modules.php).
The script then fetches the list of modules from the database using a SELECT query and stores the results
in $modules. The admin area flag ($admin_area = true) is set to enable admin-specific links. Finally, it
includes the manage modules template (include 'template/manage_modules.html.php') to display the
module management interface.
Figure 20: login.php
This PHP script handles user login functionality. It begins by including the database connection file
(include_once './include/DatabaseConnection.php') and the authentication functions file (include_once
'./include/auth.php').
The script starts a session using session_start().
When a POST request is made, it retrieves the username and password from the POST data. It then
calls getUserByUsername() to fetch user details. If a user is found and the password is verified with
password_verify(), it sets the session variables ($_SESSION['user_id'] and $_SESSION['user_role']) and
redirects to index.php.
If the login fails, it sets an error message indicating invalid credentials.
Finally, it captures the output of the login template (login.html.php) and includes the layout template
(layout.html.php) to render the complete page.
Test Image
Functionalit Desired Actual
Numbe Description
y Outcome Outcome
r
Test
User is Successful if
Validate user redirected to the outcome
login with the home page matches.
1 Login
correct with a Otherwise:
credentials. welcome "Invalid
message. username or
password."
Question is
successfully
Add a new added and
Add question user is Test
2
Question with valid redirected to Successfully
data the List
Questions
page.
Click
After deleting
Delete "Delete" in
the question Test
3 Question List
no longer Successfully
Question
exists
Test
Successful if
Correct the
Click “Edit” the outcome
module and
4 Edit Module in Manage matches.
description
Modules Otherwise:
successfully
"Module ID is
required."
IX. Challenges and Solution
Challenges
1. Integration of Frontend and Backend:
o Challenge: Ensuring that the frontend HTML forms and backend PHP scripts
communicate effectively, especially when handling user input and data submissions.
o Solution: Implemented AJAX for smooth data submission and retrieval, and validated
inputs both on the client and server sides to ensure data integrity.
2. Database Schema Adjustments:
o Challenge: Aligning the database schema with the evolving requirements of the project,
including the addition of new features and correcting issues like missing columns or
tables.
o Solution: Updated database schema and queries to reflect changes, and utilized PDO for
secure and efficient database interactions.
3. Error Handling and Debugging:
o Challenge: Managing errors such as "Column not found" or incorrect redirects which
impacted the functionality of the web application.
o Solution: Debugged and corrected PHP scripts to ensure proper handling of database
operations and redirection logic.
4. User Interface Design and Usability:
o Challenge: Designing a user-friendly interface with Tailwind CSS while maintaining a
sleek and professional appearance.
o Solution: Applied Tailwind CSS effectively to achieve the desired design aesthetics and
improved usability based on feedback.
5. Functionality Testing:
o Challenge: Ensuring all functionalities, including login, question management, and
module management, work seamlessly and meet user requirements.
o Solution: Developed comprehensive test cases to validate each functionality, including
edge cases and error scenarios.
Results
1. Successful Integration:
o Result: The integration between frontend and backend was successful, allowing for
seamless data submission and retrieval. Forms are now correctly linked to backend
processing scripts.
2. Updated Database Schema:
o Result: The database schema was updated to include necessary columns and tables.
Functionality such as adding, updating, and deleting questions and modules works as
intended.
3. Improved Error Handling:
o Result: Implemented effective error handling, reducing the incidence of common errors
and improving the robustness of the application.
4. Enhanced User Interface:
o Result: The user interface was refined to meet the design specifications, resulting in a
visually appealing and user-friendly application.
5. Validated Functionalities:
o Result: All major functionalities were tested and validated. Test cases confirmed that the
application performs correctly under expected conditions and handles errors gracefully.
Discussion
1. Integration of Frontend and Backend:
o The integration process highlighted the importance of ensuring smooth communication
between the frontend and backend. Effective error handling and validation are crucial for
maintaining data integrity and user experience.
2. Database Schema Adjustments:
o The need for schema adjustments emphasized the importance of planning database
structure in advance and being prepared to make changes as requirements evolve. Proper
schema management is essential for the stability and functionality of the application.
3. Error Handling and Debugging:
o Encountering and resolving errors provided valuable insights into common issues faced
during development. A robust error-handling mechanism is vital for building reliable web
applications.
4. User Interface Design and Usability:
o The design process reaffirmed the significance of creating an intuitive and aesthetically
pleasing interface. Tailwind CSS proved to be a powerful tool for achieving the desired
look and feel while maintaining design consistency.
5. Functionality Testing:
o The comprehensive testing approach ensured that the application meets user requirements
and performs as expected. Regular testing and validation are key to delivering a high-
quality product.
Overall, the project successfully addressed the challenges faced during development, leading to a well-
functioning and user-friendly web application. The results demonstrate the effectiveness of the solutions
implemented and provide a solid foundation for future enhancements.
X. Conclusion
The "Greenwich Confession" project successfully delivers a functional and aesthetically pleasing web
application. The design, implemented using Tailwind CSS, ensures a modern and responsive user
experience across devices.
The backend, built with PHP and PDO, provides a secure and efficient environment for managing user
interactions and data. Compliance with GDPR guidelines has been integrated to safeguard user privacy
and data protection.
The project effectively addresses various challenges, including seamless frontend-backend integration,
database schema adjustments, and robust error handling. The testing phase confirmed that core
functionalities, such as user login, question management, and administrative tools, work as expected.
Moving forward, the project has a solid foundation for further enhancement based on user feedback and
evolving requirements.