PHP/MySQLi Creating a Forum - Part 6 - Subscriptions #1

PHP/MySQLi Creating a Forum - Part 5 - Adding Ratings Introduction: This tutorial will be continuing my series of creating a forum in PHP/MySQLi/HTML. In this sixth part, I am going to show you how to add subscription options to a thread. Pre-creation: First you will need a host for your PHP, either a web host or localhost is fine but you will need PHP and MySQL(i) capabilities. Also, this will not be covering creating users, or styling the pages. For the purpose of using the logged in users username, we will be using $_SESSION['username']; from my login script, you can find that tutorial on my profile page. Obviously you will also need to go through the first, second, third, fourth and fifth parts of this tutorial series which can all be found on my profile tracking page. Please Note: The way that we are going to be doing our subscription service is the user will receive an email each time a new reply is added to the specific thread, this avoids us having to use a CronJob etc. to send one email every hour or so (if applicable). One last thing; we will be using the email from a given $_SESSION['email']; variable, simply because I don't have a user account table set up with this project just yet. If you know anything about mylsqi and php you should be able to amend this script to your liking (such as grabbing the emails from the users table within your database). Thread Page Editing: Before we do anything we need to add an option in to our thread page to allow the users to subscribe to a thread...
  1. <?php
  2.         if (isSet($_SESSION['username'])) {
  3.                 echo '<form action="subPage.php?tid='.$_GET['tid'].'" method="POST"><h1>Subscribe to Thread:</h1>Email: <input type="text" name="email" /><br/><input type="submit" name="subscribe" value="Subscribe" />';
  4.         }
  5. ?>
Now that we give them the option, we need to create a 'subPage.php' page... Database: We are going to store all of the subscriptions in our database table named 'subscriptions', create this now with the following information: id - INT - 5 Length - Primary Key - AI threadID - VARCHAR - 255 Length email - VARCHAR - 255 Length In the next part we will be editing the subPage.php page to make the subscriptions work.

Add new comment