zamp0e Posted May 27, 2009 Share Posted May 27, 2009 I've done a form where the user can vote for wich alternative he think should win, and I have a little problem with it, Is it possible to change this form so you can only vote for one alternative at once ? If so, how ? <?php if (!isset($_POST['submit'])) { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="checkbox" name="design[]" value="Stilig">Stilig <input type="checkbox" name="design[]" value="Snygg">Snygg <input type="checkbox" name="design[]" value="Helt OK">Helt OK <input type="checkbox" name="design[]" value="Lite wierd">Lite wierd <input type="checkbox" name="design[]" value="Asful">Asful <input type="checkbox" name="design[]" value="...">... <input type="submit" name="submit" value="Rösta!"> </form> <?php } else { if (is_array($_POST['design'])) { echo 'You selected: <br />'; foreach ($_POST['design'] as $a) { echo "<i>$a</i><br />"; } if($a==Stilig) { mysql_query("UPDATE roster SET antal=antal+1 WHERE id='1'")or die(mysql_error()); } } else { echo 'Nothing selected'; } } ?> Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/159859-solved-small-problem/ Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 Use SELECT multiple and then use PHP to check if the user selected more than 2. You can combine it with JavaScript to disable the selection of more than 2 options, but ultimately, you'll want PHP to do some verifications in case the user has JavaScript disabled. Link to comment https://forums.phpfreaks.com/topic/159859-solved-small-problem/#findComment-843106 Share on other sites More sharing options...
jsschmitt Posted May 27, 2009 Share Posted May 27, 2009 Use radio-buttons instead of checkboxes? Link to comment https://forums.phpfreaks.com/topic/159859-solved-small-problem/#findComment-843191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.