如何将字符串与选项值进行比较

时间:2010-04-20 02:03:21

标签: php mysql

我有这个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")

2 个答案:

答案 0 :(得分:3)

if($_POST['general'] == 'ADDRESS')

答案 1 :(得分:0)

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