Here I have two select box,one for month and other for year,for month it is working but for year in my case its coming based on current year dynamically.In the case of year when I select any option and click submit button,the option is changing and going to previous position again.Can anyone help me please. here is the code
<form action="" method="post" id="nameform">
<select name="fetchmonth">
<option <?php if ($_POST['fetchmonth'] == 'January') echo 'selected="selected"'; ?> >January</option>
<option <?php if ($_POST['fetchmonth'] == 'February') echo 'selected="selected"'; ?>>February</option>
<option <?php if ($_POST['fetchmonth'] == 'March') echo 'selected="selected"'; ?>>March</option>
</select>
<select class="boottext" name="fetchyear" required id="month" >
<?php
$expenses_year = date('Y');
// populate the select options with years
for ($yr = date("Y"); $yr >= 1970; $yr--) {
if ($yr == $expenses_year) {
echo '<option value="' . $yr . '" selected="selected">' . $yr .
'</option>';
} else {
echo '<option value="' . $yr . '">' . $yr . '</option>';
}
}
?>
</select>
</form>
<p> </p>
<button type="submit" form="nameform" value="Submit">Submit</button>