2012-09-07 69 views
-3

我想添加一个'如果和'语句,但无法让它工作。PHP如果和声明

else if($iamonly == 'Other - ' && trim($othertype == '')) { 
    echo '<div class="error_message">Error! You selected "Other"</div>'; 

如果$iamonly字段是“其他”,并输入我的$othertype现场数据,我仍然得到错误信息。请有人能告诉我我在这里做错了什么。

回答

3

trim只有变量:

if($iamonly == 'Other - ' && trim($othertype) == '') { 
+0

好了,这已经upvoted,所以我认为它应该是工作。但是,它不适合我。 – circey

+0

然后,你需要发布'$ iamonly'和'$ othertype'是什么......发布完整的输入和完整的'if'语句 –

2

此:

else if($iamonly == 'Other - ' && trim($othertype == '')) { 
    echo '<div class="error_message">Error! You selected "Other"</div>'; 

应该是这样的:

else if($iamonly == 'Other - ' && trim($othertype) == '') { 
    echo '<div class="error_message">Error! You selected "Other"</div>';