Forum project in php

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Simple PHP Forum Application

License

dprabin/simple-php-forum-application

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Simple PHP Forum Application

This is a simple PHP Forum Application created with core PHP. It uses simple Model-View-Controller (MVC) like pattern. This PHP forum Application uses Object Oriented programming to create a forum. It uses PHP Data Object (PDO) to connect to database It supports

The controller are the files at root folder of the application. They are

  • index.php: The main controller
  • create.php: Controller to create a new forum topic
  • register.php: Controller to register a user
  • topic.php: Controller to display a forum topic and manage reply to it
  • topics.php: Controller to display multiple forum topics

Models are contained in libraries folder. Classes are defined for each model containing data and methods

  • Database.php: Class used to connect to database
  • Template.php: Calss to define and manage template or view
  • Topic.php: Class to define the forum topic
  • User.php: Class to define the user
  • Validator.php: Class to validate different input forms
Читайте также:  Кнопка назад html красивая

The views are inside templates folder. Templates folder contains stylesheets, bootstrap javascripts and CKeditor files.

The core folder contains initializer code and the config folder contains configuration variables and constants. init.php reads config.php, connects to database and includes other required codes. This file is included in every controller.

The helpers folder contain helper functions that are needed by the code anywhere else. They are extensively used inside views. User avatar is stored in images/avatars and default avatar is stored in templates/img/.

To install this applicaion, create a db from talkingspace.sql file. then copy all other files to your htdocs folder and run.

Источник

Build Discussion Forum with PHP and MySQL

In this tutorial we will explain how to develop your own discussion forum system with PHP and MySQL. We have created a running forum example in this tutorial and can download complete example code to enhance this to create own forum.

Forum systems is place for people where they can start discussions on topics. The forum is controlled by administrator or moderators who creates forum categories and manage permissions for forum.

The registered members can create own discussion topics or can participate in existing discussions. The guest members also allowed to create and participate in discussions.

So let’s start developing discussion forum system with PHP and MySQL. The major files are:

  • category.php: File to list categories and category topics.
  • Category.php: A class to keep methods related to category.
  • Topics.php: A class contains methods related to topics.
  • posts.php: File to list topic posts with quick reply editor.
  • Post.php: A class contains methods related to posts.

Step1: Create MySQL Database Table

As there are categories, topics, posts in forum, so first we will create MySQL database table forum_category to store categories.

CREATE TABLE `forum_category` ( `category_id` int(11) NOT NULL, `name` varchar(255) NOT NULL, `description` text NOT NULL, `is_category` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ALTER TABLE `forum_category` ADD PRIMARY KEY (`category_id`); ALTER TABLE `forum_category` MODIFY `category_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

We will create table forum_topics to store category topics.

CREATE TABLE `forum_topics` ( `topic_id` int(11) NOT NULL, `subject` varchar(255) NOT NULL, `category_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `created` datetime NOT NULL DEFAULT current_timestamp() ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ALTER TABLE `forum_topics` ADD PRIMARY KEY (`topic_id`); ALTER TABLE `forum_topics` MODIFY `topic_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

We will create table forum_posts to store topics posts.

CREATE TABLE `forum_posts` ( `post_id` int(11) NOT NULL, `message` text NOT NULL, `topic_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `name` varchar(255) NOT NULL, `created` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ALTER TABLE `forum_posts` ADD PRIMARY KEY (`post_id`); ALTER TABLE `forum_posts` MODIFY `post_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

We will create table forum_users to store user.

CREATE TABLE `forum_users` ( `user_id` int(11) NOT NULL, `username` varchar(255) NOT NULL, `password` varchar(50) NOT NULL, `name` varchar(255) NOT NULL, `email` varchar(50) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ALTER TABLE `forum_users` ADD PRIMARY KEY (`user_id`); ALTER TABLE `forum_users` MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

Step2: Category Listing

We will implement design and functionality to list forum categories. For this, we will make changes into category.php file. We will call method getCategoryList() from class Category.php to get category list.

Читайте также:  Welcome to Your_domain!

We will implement method getCategoryList() in class Category.php to get categories from MySQL database table forum_category and return.

public function getCategoryList()< $sqlQuery = " SELECT * FROM ".$this->categoryTable." ORDER BY category_id DESC"; $stmt = $this->conn->prepare($sqlQuery); $stmt->execute(); $result = $stmt->get_result(); return $result; >

Step3: Topics Listing

We will make design changes and implement functionality to list visited category topics. For this, we will make changes in category.php file and call method getTopicList() from class Topic.php to list category topics.

We will implement method getTopicList() from class Topic.php to get category topics list from table category_topics to list topics.

public function getTopicList()< if($this->category_id) < $sqlQuery = " SELECT c.name, c.category_id, t.subject, t.topic_id, t.user_id, t.created FROM ".$this->topicTable." as t LEFT JOIN ".$this->categoryTable." as c ON t.category_id = c.category_id WHERE t.category_id ORDER BY t.topic_id DESC"; $stmt = $this->conn->prepare($sqlQuery); $stmt->execute(); $result = $stmt->get_result(); return $result; > >

Step4: Posts Listing

We will implement functionality in file post.php to list post replies of topic. For this, we will call method getPosts() from class Topic.php to list topic posts.

 
topic_id = $_GET['topic_id']; $topicDetails = $topics->getTopic(); ?> ">

getPosts(); while ($post = $result->fetch_assoc()) < $date = date_create($post['created']); $posterName = $post['username']; if($posterName == '') < $posterName = $post['name']; >?>
By:

Edit Delete
?>

We will implement method getPosts() in class Topic.php to get topic posts from table category_posts to list them.

public function getPosts()< if($this->topic_id) < $sqlQuery = " SELECT t.topic_id, p.post_id, p.message, p.topic_id, p.user_id, p.created, u.username FROM ".$this->topicTable." as t LEFT JOIN ".$this->postTable." as p ON t.topic_id = p.post_id LEFT JOIN ".$this->userTable." as u ON p.user_id = u.user_id WHERE p.topic_id ORDER BY p.post_id ASC"; $stmt = $this->conn->prepare($sqlQuery); $stmt->execute(); $result = $stmt->get_result(); return $result; > >

You may also like:

  • User Management System with PHP & MySQL
  • Datatables Add Edit Delete with Ajax, PHP & MySQL
  • Build Helpdesk System with jQuery, PHP & MySQL
  • Build Online Voting System with PHP & MySQL
  • School Management System with PHP & MySQL
  • DataTables Add Edit Delete with CodeIgniter
  • Create RESTful API using CodeIgniter
  • Build Reusable Captcha Script with PHP
  • Product Search Filtering using Ajax, PHP & MySQL
  • Image Upload and Crop in Modal with jQuery, PHP & MySQL
  • Build Push Notification System with PHP & MySQL
  • Project Management System with PHP and MySQL
  • Hospital Management System with PHP & MySQL
  • Build Newsletter System with PHP and MySQL
  • Skeleton Screen Loading Effect with Ajax and PHP
  • Build Discussion Forum with PHP and MySQL
  • Customer Relationship Management (CRM) System with PHP & MySQL
  • Online Exam System with PHP & MySQL
  • Expense Management System with PHP & MySQL

You can view the live demo from the Demo link and can download the script from the Download link below.
Demo Download

2 thoughts on “ Build Discussion Forum with PHP and MySQL ”

I added some posts and Categories in DB but only got one post
so i changed Topic.php on line 49 from
“LEFT JOIN “.$this->postTable.” as p ON t.topic_id = p.post_id”
to
“LEFT JOIN “.$this->postTable.” as p ON t.topic_id = p.topic_id”

Please help me, this tutorial is fun, the only thing that I don’t understand is how to let user login and after they can post .

Recommendations

Источник

Оцените статью