Jump to content

Voting form


xionhack

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.