So I have 2 drop down lists, I need to chose a year from them. Then I need to show the chosen year and the number of population for that year. For example:
For year 1800: the population is : 3,929,214
For year 1900: the population is : 76,212,168
Population increased by: 72,282,954.
So here is my code until now:
<html>
<head>
<meta charset="UTF-8">
<title>Calculator</title>
</head>
<body>
<h1>Population Change Calculator</h1>
<?php
$population=[3929214,5236631,7239881,9638453,12866020,17069453,23191876,31443321];
$year=(range(1790, 1860, 10));
$array= array_combine($year, $population);
?>
<form method="post">
<p><label for="year1">Year 1:</label>
<select name="year1">
<option value=""></option>
<?php
foreach ($array as $year1=>$population){ ?>
<option value="<?php echo $year1; ?>"><?php echo $year1; ?></option>
<?php }
?>
</select>
</p>
<p>
<label for="year2">Year 2:</label>
<select name="year2">
<option value=""></option>
<?php
foreach ($array as $year2=>$population){ ?>
<option value="<?php echo $year2; ?>"><?php echo $year2; ?></option>
<?php }
?>
</select>
</p>
<input type="submit" name="submit" value="Submit">
<br>
</form>
<?php
$ini_set = ini_set('display_errors', 1);
error_reporting(E_ALL);
$empty=true;
if(isset($_POST['submit'])){
if(empty($_POST['year1'])){
$empty=FALSE;
print "<p>Please choose Year 1.</p>";
}
if(empty($_POST['year2'])){
$empty=false;
print "<p>Please choose Year 2.</p>";
}
}
I cant figure out how to print the chosen year and the population for that year.
I am new to PHP, thank you in advance.