Voting form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Voting form

Post by xionhack »

Hello. I have a list of songs, all of them have a check box next to them. I also have a table for the votes. I want that if you check one or more songs and press submit, for the name of the song to be saved in the database. How can I do that? Thanks!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Voting form

Post by Christopher »

You probably need a song data table and and vote table. The song table would have and id, name, artist and whatever else you wanted. The vote table would save the song id for each vote.

I think in the form you can do something like this:

Code: Select all

<input type="checkbox" name="song[]" value="3" /> Some Song
<input type="checkbox" name="song[]" value="27" /> Another Song
<input type="checkbox" name="song[]" value="111" /> A Third Song
You would generate the checkboxes from your song data table.

The values will be in the $_POST['song'] superglobal when the form is posted. You would save those in the vote table.
(#10850)
Post Reply