What I am trying to do is select month & year and store them to variables.
The code should automatically select the month & year by default. ( It does ), but does not store the data to variables.
When I select month , it shows month correctly but on selecting year ( it show year correctly) the month changes to current month. Only the year variable is stored correctly, the month variable changes to the current month!
<?php
$month_range=array("1" =>"January","2"=>"Feburary", "3"=>"March","4"=>"April","5"=>"May","6"=>"June","7"=>"July","8"=>"August","9"=>"September","10"=>"October","11"=>"November","12"=>"December");
$year_range=range(2019, 2050);
$current_month=date('F');
$current_year=date('Y')
?>
<!DOCTYPE html>
<html lang="en">
<form>
<select name="month" onchange="this.form.submit()">
<option value=''>Select Month</option>
<?php
foreach($month_range as $month) {
$selected_month = ($month == $current_month) ? 'selected' : '';
echo '<option '.$selected_month.' value ="' .$month.'">'.$month.'</option>'; }
?>
</select>
<select name="year" id="year" onchange="this.form.submit()")>
<option value=''> Select Year</option>
<?php
foreach($year_range as $year) {
$selected_year = ($year == $current_year) ? 'selected' : '';
echo '<option '.$selected_year.' value ="' .$year.'">'.$year.'</option>';
}
?>
</select>
<?php
if(isset($_GET['year'])) {
$month=$_GET['month'];
$year=$_GET['year'];
echo $month;
echo $year;
}
?>
</form>
</html>