2010-04-20 47 views
0

我有具有选择这个HTML表单:如何字符串比较选项值

<tr> 
<td width="30" height="35"><font size="3">*List:</td> 
<td width="30"><input name="specific" type="text" id="specific" maxlength="25" value=""> 
</td> 

<td><font size="3">*By:</td> 
<td> 
    <select name="general" id="general"> 
     <font size="3"> 
     <option value="YEAR">Year</option> 
     <option value="ADDRESS">Address</option> 


    </select></td></td> 
    </tr> 

而且我想有这样的形式作用:

if ('{$_POST["ADDRESS"]}'="ADDRESS") 

哪样比较html表单中的选项中的值是否与单词“Address”匹配。如果匹配然后它会执行这个查询:

$saddress= mysql_real_escape_string($_POST['specific']);<--this is the input form where the user will put the specific address to search. 

mysql_query("SELECT * FROM student WHERE ADDRESS='$saddress'"); 

请我需要帮助在这里,我认为它错了:

if ('{$_POST["ADDRESS"]}'="ADDRESS") 

回答

3
if($_POST['general'] == 'ADDRESS') 
+0

谢谢,你是一个生命的救星。 – user225269 2010-04-20 02:58:43

0
$test=strcmp($_POST['general'],"ADDRESS"); 
if($test==0) 
{ 
    //Here you can write your operations. 
}