IF IF IF how to do it? PHP IF with syntax error

-5

In the code, there are several conditions, according to the user's choices. The system is simple, it only checks whether or not the user can receive unemployment insurance. I'm following the table:

Mycodeisasfollows:

<?php$tx=2;/*Exibeoresultadocasoavariávelpossuaumvalordiferentedenull*/if($tx!==null):if($pedido==primeira):if($meses>=12&&$meses<=23):$parcela="4";
                    elseif($meses > 23):
                        $parcela = "5"; 

                elseif($pedido == segunda):

                    if($meses >= 9 && $meses <= 11):
                        $parcela = "3";
                    elseif($meses > 11 && $meses < 24):
                        $parcela = "4"; 
                    elseif($meses > 24):
                        $parcela = "5";

                    endif;    
                endif;

            endif;   

You're giving the error:

Parse error: syntax error, unexpected end of file in > C:\wamp\www\extudando.esy.es\teste.php on line 24

and you have nothing on line 24

I also know that the syntax must be wrong (type works, but it is gambiarra), but I could not think of a more "correct" way. How could I correct this? Or the only way IF IF IF would be? And I can not fix the error

    
asked by anonymous 10.05.2018 / 23:57

1 answer

0
  • Missing endif view comment in code
  • first and second, should be enclosed in single quotation marks
  • You have to decide what happens when number of months equals 24

        if ($tx !== null): 
    
            if($pedido == 'primeira'):
    
                if($meses >= 12 && $meses <= 23):
                    $parcela = "4";
                elseif($meses > 23):
                    $parcela = "5"; 
                //faltando no seu código
                endif;
    
            elseif($pedido == 'segunda'):
    
                if($meses >= 9 && $meses <= 11):
                    $parcela = "3";
                //deve ser <=24 ?
                elseif($meses > 11 && $meses < 24):
                    $parcela = "4"; 
                //ou deve ser >=24 ?
                elseif($meses > 24):
                    $parcela = "5";
                endif; 
    
            endif;
    
        endif;
    
11.05.2018 / 02:25