COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
<HEAD>
<TITLE>::Welcome to PHP</TITLE>
</HEAD>
<BODY>
<h4>Form variable</h4>
<table>
<form action=ex4.php method=get>
<tr><td>Province:<select name=province>
<option value=HAN>Ha Noi</option>
<option value=HCM>Ho Chi Minh</option>
<option
value=HUE>Hue</option>
</select>
<input type=submit value=Submit></td></tr>
</form>
<tr><td>
<?php
if(isset($HTTP_GET_VARS["province"]))
{
$result=$HTTP_GET_VARS["province"];
echo
"Result:
".$result;
}
?>
</td></tr>
</table>
</BODY>
</HTML>
Löu yù raèng, neáu baïn khoâng söû duïng haøm isset ñeå kieåm tra province toàn taïi hay khoâng
thì trang php seõ phun loãi trong tröôøng hôïp laàn ñaàu tieân goïi ñeán trang ex4.php maø
khoâng submit. Tuy nhieân, neáu baïn submit trang naøy thì keát quaû traû veà nhö hình 4-4.
Hình 4-4: Duøng $HTTP_GET_VARS
Töông töï nhö vaäy trong tröôøng hôïp baïn khoâng söû duïng theû form maø giaù trò laáy töû chuoãi
QueryString baèng caùch söû duïng $HTTP_GET_VARS nhö ví duï 4-5.
Ví duï 4-5: Söû duïng $HTTP_GET_VARS
<HTML>
<HEAD>
<TITLE>::Welcome to PHP</TITLE>
</HEAD>
Giaùo vieân: Phaïm Höõu Khang