2012-09-07 62 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>';