2012-09-07 3 views
-3

'if 및'문을 추가하려고하는데 작동하지 않습니다. $iamonly 필드가 '기타'내가이 $othertype 필드에 데이터를 입력PHP if 및 statement

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

경우에, 나는 여전히 오류 메시지가 표시됩니다. 누군가 여기서 내가 잘못하고있는 것을 말해 줄 수 있습니까?

답변

3

trim에만 변수 :이 이렇게 upvoted 된

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

그럼 나는 그것이 작동해야 가정합니다. 그러나, 그것은 나를 위해 작동하지 않습니다. – 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>';