Homework Assignment #7
 
Topic: PHP and MySQL
Due Date: March 2nd
 

Objectives:

  • to experiment with MySQL
  • to explore the PHP/MySQL connection

Assignment:

Create an application using PHP and MySQL that will accept user's votes for songs and tabulate them.  The user should be able to request a report of the number of votes for all the songs.

PART 1: Create a table of songs in your MySQL database.  Include fields for song title and number of votes.  Populate it with several songs to test it.

PART 2: Write a PHP page that gives the user the option of voting for a new song or one that is already in the database.  The form should have a text box for entering a new song and a selection list to vote for an existing song.  The selection list should have all the songs currently in the database in alphabetical order.

Use a JavaScript function to make sure the user doesn't enter a song in the text box that is already in the selection list.  The function should be called when the user tries to submit the form.  Add an onsubmit attribute to the form tag to call the function and receive the return value (e.g. onsubmit = "return checkSong();")  The function should return true if the input data is valid or false if it is not.  The "onsubmit" will allow the form action to proceed if the return value is true or block it, if the function returns false.

Include a second form on the page with a submit button for the user to request the vote summary for all songs.

PART 3: Write the PHP page to record the user's vote.  If the text box is filled in, the script should add the new song to the table with a vote count of 1.  Otherwise, the script should add to the vote count for the song selected from the list.  The page should display the song title the user entered and its current number of votes.

PART 4: Write the PHP page to display the vote count summary.  This should list the songs in order of popularity.  To sort in descending order, add the keyword DESC after the sort field name (... ORDER BY sort_field DESC ...).

PART 5: Name and publish your PHP data collection page so that its URL is "http://rotini.union.edu/~username/csc240/hw/hw7". 

Turn In:

Printouts of your PHP data collection page, vote recording page and summary page.  If you put your scripts in external files, print the external script files also.



Page last updated on Thursday February 23, 2006 10:24 AM
by L. Almstead, Union College, Schenectady, NY 12308
Home Page URL: http://cs.union.edu/csc240/