xionhack Posted November 25, 2009 Share Posted November 25, 2009 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! Link to comment https://forums.phpfreaks.com/topic/182863-voting-form/ Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 You could do something like this: Particularly, look at the name="" attribute for the checkbox-inputs. What those [] do is indicate that any checked values will go into an array. Also keep in mind, the value="" attribute for the checkboxes can be anything, numbers, names of songs, etc. -- this is a very basic example. <?php if(isset($_POST['action'])){ foreach($_POST['songs'] as $song){ mysql_query("INSERT INTO `table`..."); } } echo '<form action="foobar.php" method="post">'; echo '<input type="checkbox" name="songs[]" value="NAME_OF_SONG_1"> NAME_OF_SONG_1<br />'; echo '<input type="checkbox" name="songs[]" value="NAME_OF_SONG_2"> NAME_OF_SONG_2<br />'; echo '<input type="checkbox" name="songs[]" value="NAME_OF_SONG_3"> NAME_OF_SONG_3<br />'; echo '<input type="checkbox" name="songs[]" value="NAME_OF_SONG_4"> NAME_OF_SONG_4<br />'; echo '<input type="checkbox" name="songs[]" value="NAME_OF_SONG_5"> NAME_OF_SONG_5<br />'; echo '<input type="checkbox" name="songs[]" value="NAME_OF_SONG_6"> NAME_OF_SONG_6<br />'; echo '<input type="submit" name="action" value="Vote"></form>'; ?> Link to comment https://forums.phpfreaks.com/topic/182863-voting-form/#findComment-965210 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.