'How can i call a function that executes an fpdf based on the choice of a form selector?

I am trying to create FPDF's with different formats, which are inside a file of functions that are called through a form on another page inside the field selector = muni, but it is not respecting me the if and always takes the first function, could you guide me?

This is the form

<form id="clientForm" name="formularioDatos" method="post" action="insertBD.php"  target="print_popup" 
  onsubmit="window.open('about:blank','print_popup','width=1000,height=800');">

<div class= col-md-3>
    <select class="form-control input-lg" id="idMunicipio" name="idMunicipio" #>
        <option value="" #>MUNICIPIO</option>
        <option value="ACOLMAN">ACOLMAN</option>
        <option value="ZUMPANGO">ZUMPANGO</option>
    </select>
    <input id="muni" name="muni" hidden="true">
</div>
<script>
    $("#idMunicipio").change(function () {
    // aqui vuelve a colocar el id de tu select, pero en esta ocación detectamos el valor que tiene el mismo
    $("#idMunicipio option:selected").each(function () {
        // luego guardas el valor en una variable
        var muni = $(this).val();
        $("#muni").val(muni);
    });
});
</script>

This is de insertion in db:

<?php 

include ("pdffunctions.php");
include("conn.php");
$con = connect();
$muni = mysqli_real_escape_string($con, $_POST['muni']);
$way_pay = mysqli_real_escape_string($con,$_POST['way_pay']);
$amount = mysqli_real_escape_string($con,$_POST['amount']);
$concept = mysqli_real_escape_string($con,$_POST['concept']);
$file_name = date("Y-m-d") . "_". $rfc.".pdf";

$sql = "INSERT INTO naucalpan(muni, way_pay, amount, concept, )VALUES('$muni', '$way_pay', '$amount', '$concept', )";
$query= mysqli_query($con, $sql);
if ($muni == 'NAUCALPAN' OR 'HUIXQUILUCAN' )
{
    nau($muni, $way_pay, $concept, $file_name);
}
elseif($muni == 'ACOLMAN' OR 'ATENCO' OR 'AXAPUSCO' OR 'CHIAUTLA' OR 'CHICOLOAPAN' OR 'CHICONCUAC' OR 'CHIMALHUACAN' OR 'NOPALTEPEC' OR 'OTUMBA' OR 'PAPALOTLA' OR 'LA PAZ' OR 'SAN MARTIN DE LAS PIRAMIDES' OR 'TEOTIHUACAN' OR 'TEPETLAOXTOC' OR 'TEXCOCO' OR 'TEZOYUCA')
{
    tex( $muni, $way_pay, $concept, $file_name);
}

And here my functions in pdffunctions.php

<?php
    require('fpdf/fpdf.php');
    class PDF extends FPDF
    {}

    function nau( $muni, $way_pay, $concept, $file_name){
        
        $pdf = new FPDF();
        $pdf->AddPage();
        $pdf->SetTextColor(56,56,56);
        $pdf->SetFont('Arial','B',7);
        $pdf->SetMargins(10,10,10,10);
        $pdf->SetY(53);
        $pdf->Setx(45);
        $pdf->Cell(45,12,utf8_decode(''.$muni),0, 0, 'L');
        $pdf->Ln();
        $pdf->Setx(45);
        $pdf->Cell(45,12,utf8_decode(''. $way_pay),0, 0, 'L');
        $pdf->SetY(56);
        $pdf->Setx(108);
        $pdf->MultiCell(60, 12, utf8_decode(''. $concept."    TLANEPANTLA"),0, 0, 'L');
        $pdf->Ln();

        $pdf->Output('F', "pdfs/$file_name");
        $pdf->Output();
    };

    function tex($muni, $way_pay, $concept, $file_name){
        
        $pdf = new FPDF();
        $pdf->AddPage();
        $pdf->SetTextColor(56,56,56);
        $pdf->SetFont('Arial','B',7);
        $pdf->SetMargins(10,10,10,10);
        $pdf->SetY(53);
        $pdf->Setx(45);
        $pdf->Cell(45,12,utf8_decode(''.$muni),0, 0, 'L');
        $pdf->Ln();
        $pdf->Setx(45);
        $pdf->Cell(45,12,utf8_decode(''. $way_pay),0, 0, 'L');
        $pdf->SetY(56);
        $pdf->Setx(108);
        $pdf->MultiCell(60, 4, utf8_decode(''. $concept."TEXCOCO"),0, 0, 'L');
        
            $pdf->Output('F', "pdfs/$file_name");
            $pdf->Output();
        }
?>


Solution 1:[1]

Your php if statements are based on a misunderstanding.

if ($muni == 'NAUCALPAN' OR 'HUIXQUILUCAN' ) 

must be

if ($muni == 'NAUCALPAN' OR $muni == 'HUIXQUILUCAN' )

for example.

In your version, the OR is evaluated first, so it calculates 'NAUCALPAN' OR 'HUIXQUILUCAN' as an expression, which evaluates to true (because populated strings are truth-y) , so your if ends up as if ($muni == true) which, with a populated value and a loose type comparison, will always end up being true as well (demo: https://3v4l.org/FbdIC).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ADyson