Multiple Selection With PHP

Category: PHP, HTML
Reviewed by: Chiggins   
Reviewed on: Oct 28 2008
» Discuss this topic ( Posts)

 
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Item One <input type="checkbox" name="item[]" value="one" />
    Item Two <input type="checkbox" name="item[]" value="two" />
    Item Three <input type="checkbox" name="item[]" value="three" />
    Item Four <input type="checkbox" name="item[]" value="four" />
    Item Five <input type="checkbox" name="item[]" value="five" />
</form>
 
<?php
if ( isset( $_POST['item'] ) ) {
    foreach ( $_POST['item'] as $item ) {
        echo "You selected item number " . $item . "<br />";
    }
}
?>