retain selected from dropdown value in php
<p>I wanted to retain selected from dropdown value after submit. </p>

<p>I tried the code below but it still returned to previous one. Could not return the selected one.</p>

<pre><code>&lt;?php $attr = 'selected="selected"'; ?&gt;
&lt;?php $colname = isset($_REQUEST['colname']) ? $_REQUEST['colname'] : null; ?&gt;
&lt;select name="colname" style="margin-bottom:3px;"&gt; 
&lt;option value="value1" &lt;?php echo $colname == 'Value1' ? $attr : ''; ?&gt;&gt;value1&lt;/option&gt;
&lt;option value="value2" &lt;?php echo $colname == 'Value2' ? $attr : ''; ?&gt;&gt;value2&lt;/option&gt;
&lt;option value="value3" &lt;?php echo $colname == 'Value3' ? $attr : ''; ?&gt;&gt;value3&lt;/option&gt;
&lt;option value="value4" &lt;?php echo $colname == 'Value4' ? $attr : ''; ?&gt;&gt;value4&lt;/option&gt;
&lt;/select&gt;
</code></pre>
