Homework 2

Due February 20th, 11:59pm

Submission Instructions

As with all homeworks, you will submit this project in a two-step process:

Make sure your name, email address, and eid are in a comment at the top of each file you submit.


For this assignment, you'll be integrating a mysql database into the social networking site you created for the first homework. You'll be using the database to implement persistent relationships between the members of your network. You'll also be using sessions and cookies to give users a smooth experience while navigating the network. Of course, this submission needs to retain the functionality of the previous one.

For this assignment, you need to implement these two key features in the following ways:

  1. Using sessions to keep track of users.
    • The index of your website will now be a login page (think facebook) on which users can enter their username and password to login. Logging in will start a new session and take users to their profile. There should also be a link to the signup page.
    • Include a toolbar on each webpage that has a link which takes the logged-in user to their profile, a link to edit their profile, a link to the search feature (see below), and a link to log out (end the session).
    • Posting a message on a profile now requires someone to be logged in- a message will now display when it was posted and who posted it.
  2. Using mysql to store data about the users of the network
    • You need to design a database to store network information. There should be at least three tables:
      1. A user information table: user ids, passwords, profile info.
      2. A messages table for storing posted messages. In addition to the message, you need to keep track of who posted the message and when it was posted.
      3. A connection table that stores friendship relationships.
      Your submission needs to include a mysql script that sets up your database and populates it with at least seven users and a couple of relationships. This should look something like the SQL Walkthrough on the course website.
    • The signup page now needs to collect a user id. Email address are fine for ids. Your validation procedures should be updated to check that this id is not already in the user database. Thus, each row in the users table should have a unique id (*cough* these would be ideal primary keys *cough*). Validated data should now be inserted into the database. Instead of showing the profile, a successful signup can just take users to a page thanking them for signing up.
    • You still need a page for editing profiles, but the form should now be populated with data from the database. You should use session variables to ensure that only a logged-in user can edit their profile.
    • The profile page should now use the database to get profile information. I would suggest designing the php page to use GET to identify the user id to display. This will let you provide links to specific profiles by putting ids in the url. You will also need to display a list of all messages posted to a user's wall by querying the messages table.
    • Profile pages should now have an "add friend" button, if there is a user currently logged in (you should use session variables to check this). Friend relationships should be added to the database.
    • Profile pages should now display a list of a user's friends.
  3. You need to have a search page. This should just query the database and return all users whose names match the search term. Each result should have a link to that the profile page for that user.

Bonus Points

Add privacy setting to messages. Users can select a privacy level when posting a message- 'friends' or 'everybody'. The profile webpage should use session info to determine whether or not to display a message. If no one is logged in, only 'everybody' messages should be displayed.