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

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

Insert session variable into MySQL database

Insert CheckBox and Radio button Data in MySQL Database Using PHP