How to Keep the selected value of the select box after Form POST or GET

<?php
$example = $_POST["friend"];
?>
<form method="POST">
<select name="friend">
   <option value="tom" <?php if (isset($example) && $example=="tom") echo ' selected';?>>Thomas Finnegan</option>
   <option value="anna" <?php if (isset($example) && $example=="anna") echo ' selected';?>>Anna Karenina</option>
</select>
<br><br>
<input type="submit">
</form

Comments

Popular posts from this blog

Script For Login, Logout and View Using PHP, MySQL and Bootstrap

Real-Time Web Interface to MQTT using Socket.io and Node.js

Customize radio buttons and checkboxes with CSS sprites