-1

My first page is checkbox form

    <!DOCTYPE html>
<html>
<body>

<form action="1.php" method="POST">
<input type="checkbox" name="count" value="count">count<br>
<input type="checkbox" name="search" value="search">search<br>
<input type="checkbox" name="order" value="order">order 
<input type="submit" value ="submit">
</form>

</body>
</html>

Then my next page is collecting the values using post and by using if conditions displaying the result

  <?php
    if(empty($_POST['count'])) { 
           $_POST['count']=''; 
        }
        else { 
            $a=$_POST['count']; 
        }
        if(empty($_POST['order'])) {
            $_POST['order']=''; 
        }
        else { 
            $b=$_POST['order']; 
        }
         if(empty($_POST['search'])) {
            $_POST['search']=''; 
        }
        else { 
            $c=$_POST['search']; 
        }

       if($_POST['count']=="count" && $_POST['search']=="search" && $_POST['order']=="order" )  {
          echo  "I have a count ,search and order" ;
       } 
        else if($_POST['order']=="order" && $_POST['count']=="count" && $_POST['search']!="search"  )  {
           echo "I have a order and count";
        }
        else if($_POST['search']=="search" && $_POST['count']=="count" && $_POST['order']!="order"  )  {
           echo "I have a search and count";
        }
         else if($_POST['search']=="search" && $_POST['order']=="order" && $_POST['count']!="count"  )  {
           echo "I have a search and order";
        }           
       else if($_POST['count']=="count" || $_POST['search']=="search" || $_POST['order']=="order"  ) {
          echo $_POST['count'];
          echo $_POST['search'];
          echo $_POST['order'];
       }
?>

I have a bike condition is working

I have a car condition is working

I have a car and bike is not working , I am new to this language so plz help

4

4 回答 4

3

你试试:

...
if($_POST['vehicle']=="Bike" && $_POST['vehicle1']=="Car")  {
       echo  "I have a car and bike" ;
} else if($_POST['vehicle']=="Bike") {
        echo "I have a bike";
} else if($_POST['vehicle1']=="Car") {
       echo  "I have a car" ;
}

“汽车和自行车”不起作用,因为条件 1 为真 => 条件 2 和 3 不再测试。

IF - Else if:如果条件 1 为假,则检查条件 2,如果条件 2 为假,则检查条件 3。

于 2013-08-08T06:45:34.117 回答
1

删除else并尝试喜欢

<?php

if ($_POST['vehicle'] == "Bike" && $_POST['vehicle1'] == "Car")  {
   echo "I have a car and bike" ;
} else if ($_POST['vehicle'] == "Bike") {
    echo "I have a bike";
} else if ($_POST['vehicle1'] == "Car") {
   echo "I have a car" ;
}

?>    
于 2013-08-08T06:34:55.407 回答
0

您的代码将更新到最后一条elseif语句。我会将最后一个 else if 语句移到顶部。

    <?
    if(empty($_POST['vehicle'])) { 
           $_POST['vehicle']=''; 
        }
        else { 
            $a=$_POST['vehicle']; 
        }
        if(empty($_POST['vehicle1'])) {
            $_POST['vehicle1']=''; 
        }
        else { 
            $b=$_POST['vehicle1']; 
        }
       if($_POST['vehicle']=="Bike" && $_POST['vehicle1']=="Car")  {
          echo  "I have a car and bike" ;
       } 
        else if($_POST['vehicle']=="Bike") {
           echo "I have a bike";
        }       
       else if($_POST['vehicle1']=="Car") {
          echo  "I have a car" ;
       }
?>
于 2013-08-08T06:38:33.257 回答
0
    if(empty($_POST['vehicle'])) { 
       $_POST['vehicle']=''; 
    }
    else { 
        $a=$_POST['vehicle']; 
    }
    if(empty($_POST['vehicle1'])) {
        $_POST['vehicle1']=''; 
    }
    else { 
        $b=$_POST['vehicle1']; 
    }
    if($_POST['vehicle']=="Bike" && $_POST['vehicle1']!="Car") {
       echo "I have a bike";
    }       
   elseif($_POST['vehicle1']=="Car" && $_POST['vehicle']!="Bike") {
      echo  "I have a car" ;
   }
   if($_POST['vehicle']=="Bike" && $_POST['vehicle1']=="Car")  {
      echo  "I have a car and bike" ;
   } 
于 2013-08-08T06:34:23.890 回答