If/else-If语句不适用于PHP表单过滤器


If/else if statements not work with PHP form filter

我试图弄清楚为什么当我提交这个表单过滤器时,我的if/else-if语句不起作用。print_r($post);返回正确的过滤器值,但是无论选择了什么过滤器选项,$printmain都只显示"康复"-这很奇怪,因为$post变量明显在变化。所以我不明白为什么它不通过if/else-if语句?

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>

在if语句中使用=而不是==

更改以下内容:

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';}

您需要知道=(一个赋值运算符)和==(一个比较运算符)之间的区别