Update variable in IF

Asked

Viewed 52 times

0

Good morning,

I am unable to update a variable within the IF structure and use it later in my code.

Follows excerpt from my code:

while ($dado_participante = mysqli_fetch_array($qry2)) { 

    //REGISTRO 0150: TABELA DE CADASTRO DO PARTICIPANTE 

    $cod_part++; //FAZER UM CONTADOR 
    $nome_part = $dado_participante['RAZAO_SOCIAL']; 
    $cod_pais_part = '01058'; 
    $cpf_part = limpa_caracteres_especiais($dado_participante['CPF']); 
    $cnpj_part = limpa_caracteres_especiais($dado_participante['CPF']); 

    if (strlen($cnpj_part == 14)){ 

        $cpf_part = ''; 

    } 

    elseif(strlen($cpf == 11)){ 

        $cnpj_part = ''; 

    } 

    $insc_estadual_part = ''; //Inscrição Estadual do participante. 
    $cod_mun_part = $dado_participante['COD_CIDADE']; 
    $suframa_part = ''; 
    $end_part = $dado_participante['ENDERECO']; 
    $num_part = ''; 
    $compl_part = $dado_participante['COMPLEMENTO']; 
    $bairro_part = $dado_participante['BAIRRO']; 

    //0150 
    $txt .= '|0150|' . $cod_part . '|' . $nome_part . '|' . $cod_pais_part . '|' . $cnpj_part . '|' . $cpf_part . '|' . $insc_estadual_part . '|' . $cod_mun_part . '|' . $suframa_part . '|' . $end_part . '|' . $num_part . '|' . $compl_part . '|' . $bairro_part . '|' . PHP_EOL; 

} 

Yes, the cpfs and cnjps are in the same column in the database, so I did if to try to differentiate them when printing in my code.

For when cnpj print Fps blank and vice versa.

1 answer

0


The error is here:

    if (strlen($cnpj_part) == 14){ 

        $cpf_part = ''; 

    } 

    if(strlen($cpf_part) == 11){ 

        $cnpj_part = ''; 

    } 

In your code you were comparing strlen within the function, the top code should work.

  • Thanks but the error remains. Variables are not being updated by the if structure.

  • If you give echo $cnpj_part. $cpf_part' it returns something ?

  • Thank you! Your suggestion really worked. When copying your code snippet I copied "$Cpf" instead of " $cpf_part ". Thank you so much for your help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.