Checkboxes with php Database

Asked

Viewed 509 times

0

Good afternoon.

I ask from now on to re-read my little programming experience. In case my question does not fit well with the theme that I will present, I ask you to excuse me. I ask for your help and collaboration.

I’m doing a garage project where I have two check boxes. One that selects the vehicle by the license plate and another that selects the driver by name. Below the layout

 

imagem1  

When I select the vehicle, it scans the database for all of its data. The fields from which it will deposit the data that will be fetched from the selected item are bypassed by the red lines.

The employee checkbox is the same dilemma, however, are the fields of the green line.

Basically, I select the vehicle’s license plate / driver’s name and so a query is made using the driver’s license plate or name in the Where. I will try to explain in more detail:

When selecting the item, it will "reload" the page and will bring the value selected by the "$_POST", as:

 

Plate selection box:

    <select id="placas" name="placa" onclick="if (this.value != ''){this.form.submit()};">
        <option value="">- PLACAS -</option>
    <?php
        $i=0; 
        while(odbc_fetch_row($sql))
            { 
                $i++;
            $placa=odbc_result($sql,"PLACA");
    ?>                      
            <option value="<?php echo $placa; ?>" ><?php echo $placa; ?></option>
          <?php } ?>
    </select>

&nbsp;

$_POST: 

    $var = $_POST['placa'];

From this point, it will use the "$var" variable to filter the query. How:

    $sql1 =  odbc_exec($conn1," SELECT  ID_FLASHPT AS 'ID', 
                                                    NOME_VEICULO AS 'NOME',
                                                    PLACA_VEICULO AS 'PLACAS',
                                                    MARCA_VEICULO AS 'MARCA',
                                                    QUILMT_VEICULO AS 'QUILOMETRO',
                                                    DOCMT_VEICULO AS 'DOCUMENTO',
                                                    COR_VEICULO AS 'COR',
                                                    COMBTVL_VEICULO AS 'COMBUSTIVEL',
                                                    ANO_MODL_VEICULO AS 'MODELO',
                                                    ANO_FABRC_VEICULO AS 'FABRICACAO',
                                                    OBS_VEICULO AS 'OBS'
                                        FROM        FLASHPT
                                        WHERE   PLACA_VEICULO = '$var'");

&nbsp;

In this case a filter would be made from the variable '$board' or '$driver' present in Where da Query.

Until then, it works. When selecting the option, it will "reload" the page and bring the selected value in the card checkbox by $_POST and write to a variable (in this case, the "$var") and so uses this variable to query and stores filter values in variables that will be passed to inputs. Like:

 

Values that will be filtered from "$var" and stored in variables so that they are passed to an input, right after.

    $nome=odbc_result($sql1,"NOME");
    $marc=odbc_result($sql1,"MARCA");
    $quil=odbc_result($sql1,"QUILOMETRO");
    $doc=odbc_result($sql1,"DOCUMENTO");
    $cor=odbc_result($sql1,"COR");
    $comb=odbc_result($sql1,"COMBUSTIVEL");
    $mod=odbc_result($sql1,"MODELO");
    $fab=odbc_result($sql1,"FABRICACAO");
    $placas=odbc_result($sql1,"PLACAS");
    $obsveiculo=odbc_result($sql1,"OBS");

&nbsp;

Inputs: These inputs are the ones circled by red or green lines, in the image right above.

    <input type="text" maxlength="10" minlength="8" required placeholder="Placa" disabled style="font-size: 15pt;" value="<?php echo $placas ?>" name="placaveiculo">

&nbsp;

However, when I select the board and so reload the page bringing the values that are in the inputs circled in red (the same way that this in the image above) and then select the driver, by reloading the page again to bring the driver’s data this time, he brings the driver’s data correctly, however, he erases the vehicle data and so on.

I ask you to help me, if I have not had clarity in my doubt, ask me that I try to specify my explanation better

Thank you in advance.

1 answer

0

You will have to work with $_GET IF(ISSET()) In my view it would look something like this.

if(isset($_GET['Placa']) AND isset($_GET['Motorista'])){
$placa=$_GET['placa'];
$motorista=$_GET['Motorista'];
Aqui vc faz o Sqqlect
exemple
select id from ex where motorista =$motorista and placa=$placa
}elseif(isset($_GET['Placa'])){
$placa=$_GET['placa'];
Aqui vc faz o Sqqlect
exemple
select id from ex where  placa=$placa
}esleif(isset($_GET['Motorista'])){
$motorista=$_GET['Motorista'];
Aqui vc faz o Sqqlect
exemple
select id from ex where motorista =$motorista 
}else{}

Browser other questions tagged

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