2014-10-22 3 views
1
확인하십시오!

내 사이트에이 입력란이 있는데 어떻게 드롭 다운으로 대체하여 여전히 query.php 파일로 데이터를 전송할 수 있습니까? 드롭 다운없이 잘 작동하지만 사용자가 더 쉽게 사용할 수 있도록 모든 연도를 코드에 포함하지 않기 때문에 드롭 다운을 추가하려고합니다.입력 대신 드롭 다운

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> 
+0

''태그를 만들고 생성한다. 그것의'

답변

0

이 코드 년 이상을 추가 할 수있는 옵션을 추가

<select id="year" name="year"> 
    <option value="1980" selected>1980</option> 
    <option value="1981">1981</option> 
</select> 

보관할 대한 HTML 입력을 교체합니다.

연도를 포함하는 $ _POST [ 'year']를 찾을 수 있습니다. 누구나 브라우저에서 HTML 페이지를 수정하고 삽입하려는 악의적 인 가치를 포함하는 추가 옵션 태그를 추가 할 수 있기 때문에 이것은 입력을 검증하는 방법이 아닙니다.

+0

이것은 개인 용도로 사용하는 것입니다. 실제로 온라인 상태가 아닙니다. – masterbeat

+0

고맙습니다. 작동합니다. D – masterbeat

관련 문제