dimanche 1 novembre 2020

How to use && opertor with checkboxes in php

I am trying to fetch data from MySQL database in PHP based on checkbox selected. i am fine when a single checkbox is selected then it should fetch me some data from the database, but when two or more checkboxes are selected it is not fetching the right data but coming as if it is only one checkbox selected.

example:

checkbox1 to display firstname, checkbox2 to display lastname. when checkbox1 and checkbox2 are selected should display firstname and lastname but it is only displaying firstname.

if(isset($_POST["Export"])){

    if(isset($firstname)){

        $sql = "SELECT firstname from biodata";
        $stmt = $pdo->query($sql);
    }
    elseif(isset($lastname)){

        $sql = "SELECT lastname from biodata";
        $stmt = $pdo->query($sql);
    }
   
    if(isset($firstname && $lastname)){

        $sql = "SELECT firstname,lastname from biodata";
        $stmt = $pdo->query($sql);
    }
}



Aucun commentaire:

Enregistrer un commentaire