2013-12-09 3 views
1

이 양식 필터를 제출할 때 if/else if 문이 작동하지 않는 이유를 알아 내려고하고 있습니다. print_r ($ post); 올바른 필터 값을 반환하지만 $ printmain은 어떤 필터 옵션이 선택 되더라도 '재활 치료'만 표시합니다. 이는 $ post 변수가 분명히 변하기 때문에 이상합니다. 그래서 if/else if 문을 사용하지 않는 이유를 알 수 없습니까? 귀하의 경우 문에서 당신이 =를 사용하는 대신 ==된다If/else if 문이 PHP 양식 필터와 작동하지 않습니다.

if(isset($_POST['filter'])) { 

    $post = $_POST['filter']; 

     print_r($post); 

     if ($post = 'teamrehab') {$printmain = 'rehab';} 
     else if ($post = 'heights') {$printmain = 'heights';} 
     else if ($post = '1225') {$printmain = '1225';} 

    } 

<html> 
    <form method="post" id="filter" action="<?= $_SERVER['PHP_SELF'];?>"> 
    <select name="filter" onchange="document.getElementById('filter').submit();"> 
    <option value="choose">Choose Client</option> 
    <option value="teamrehab">teamrehab</option> 
    <option value="heights">heights</option> 
    <option value="1225">1225 Old Town</option> 
    </select> 
    </form> 

<?php if(!empty($_SESSION['username'])){ echo $printmain;} 
else echo "Please login with your Twitter account.";?> 


</html> 
+1

하여 비교 연산자'인 assignment operator== = '=='를 비교하지 않는 값을 할당하고있다. – hammus

답변

3

.

변경 다음

if ($post = 'teamrehab') {$printmain = 'rehab';} 
     else if ($post = 'heights') {$printmain = 'heights';} 
     else if ($post = '1225') {$printmain = '1225';} 

에 :

if ($post == 'teamrehab') {$printmain = 'rehab';} 
     else if ($post == 'heights') {$printmain = 'heights';} 
     else if ($post == '1225') {$printmain = '1225';} 

당신이 =의 차이를 알아야 할 comparison operator

관련 문제