1// Page containing a form:
2<form action="myaction.php" method="post">
3 <select name="fruit">
4 <option value="Apple">Apple</option>
5 <option value="Banana">Banana</option>
6 </select>
7 <input type="submit" value="Submit">
8</form>
9
10// myaction.php
11Hello <?php echo htmlspecialchars($_POST['fruit']); ?>
1<?php
2
3$selection = array('PHP', 'ASP');
4echo '<select>
5 <option value="0">Please Select Option</option>';
6
7foreach ($selection as $selection) {
8 $selected = ($options == $selection) ? "selected" : "";
9 echo '<option '.$selected.' value="'.$selection.'">'.$selection.'</option>';
10}
11
12echo '</select>';