I have this input field for my site, how could i replace it with a drop down so it still sends data to the query.php file? It works fine without the dropdown but i want to add the dropdown becaus ei am not including every Year in the code so it will be just easier for the user.
php:
<?php
$input = $_POST["textarea"];
echo 'In year '. $input .' the population of the world was:';
echo "<br />";
if($input == 1980){
echo "1980-";
}elseif($input == 1981){
echo "You did not write a";
}elseif($input == 1982){
echo "You did not write a";
}elseif($input == 1983){
echo "You did not write a";
}elseif($input == 1984){
echo "You did not write a";
}elseif($input == 1985){
echo "You did not write a";
}elseif($input == 1986){
echo "You did not write a";
}elseif($input == 1987){
echo "You did not write a";
}elseif($input == 1988){
echo "You did not write a";
}elseif($input == 1989){
echo "You did not write a";
}elseif($input == 1990){
echo "You did not write a";
}elseif($input == 1991){
echo "You did not write a";
}elseif($input == 1992){
echo "You did not write a";
}elseif($input == 1993){
echo "You did not write a";
}elseif($input == 1994){
echo "You did not write a";
}elseif($input == 1995){
echo "You did not write a";
}elseif($input == 1996){
echo "You did not write a";
}elseif($input == 1997){
echo "You did not write a";
}elseif($input == 1998){
echo "You did not write a";
}elseif($input == 1999){
echo "You did not write a";
}elseif($input == 2000){
echo "You did not write a";
}elseif($input == 2001){
echo "You did not write a";
}elseif($input == 2002){
echo "You did not write a";
}elseif($input == 2003){
echo "You did not write a";
}elseif($input == 2004){
echo "You did not write a";
}elseif($input == 2005){
echo "You did not write a";
}elseif($input == 2006){
echo "You did not write a";
}elseif($input == 2007){
echo "You did not write a";
}elseif($input == 2008){
echo "You did not write a";
}elseif($input == 2009){
echo "You did not write a";
}elseif($input == 2010){
echo "You did not write a";
}elseif($input == 2011){
echo "You did not write a";
}elseif($input == 2012){
echo "You did not write a";
}elseif($input == 2013){
echo "You did not write a";
}elseif($input == 2014){
echo "You did not write a";
}else{
echo "Syntax error: You wrote in a wrong year!";
}
?>
html:
<form method="post" action="query.php">
<input type="text" class="form-control" id="textarea" placeholder="Year">
<button type="submit" name="inputuno" value="Submit" class="btn btn-theme">Check!</button>
</form>
Replace your html input for this code
<select id="year" name="year">
<option value="1980" selected>1980</option>
<option value="1981">1981</option>
</select>
Keep adding option to add more years.
You will find the $_POST['year'] to contain the year. Note that this is not a way to validate an input because anyone can modify your html page in their browser and add an extra option tag that will contain whatever evil value they want to put in.