I wanted to retain selected from dropdown value after submit.
I tried the code below but it still returned to previous one. Could not return the selected one.
<?php $attr = 'selected="selected"'; ?>
<?php $colname = isset($_REQUEST['colname']) ? $_REQUEST['colname'] : null; ?>
<select name="colname" style="margin-bottom:3px;">
<option value="value1" <?php echo $colname == 'Value1' ? $attr : ''; ?>>value1</option>
<option value="value2" <?php echo $colname == 'Value2' ? $attr : ''; ?>>value2</option>
<option value="value3" <?php echo $colname == 'Value3' ? $attr : ''; ?>>value3</option>
<option value="value4" <?php echo $colname == 'Value4' ? $attr : ''; ?>>value4</option>
</select>
I would confirm this by viewing your outputted source, but I suspect that you are not passing colname properly to the REQUEST (or you are setting the value of $_REQUREST[‘colname’] elsewhere in your script). The rest of your code look sound.