Update does not find what was typed in the inputs

1

I have a system where you can change the information of a record through an editing form, but this edition is not being saved.

HTML

<?php
                    $lnk = mysqli_connect('localhost','root','') or die(mysql_error());
                            mysqli_select_db($lnk,'banco') or die(mysql_error());

                    $query = mysqli_query($lnk, "SELECT PILOTE FROM qualite");
                    $kpi = filter_input(INPUT_POST, 'KPI');
                    $pilote = filter_input(INPUT_POST, 'PILOTE');
                    $janPrev = filter_input(INPUT_POST, 'JAN PREV');
                    $janReal = filter_input(INPUT_POST, 'JAN REAL');
                    $fevPrev = filter_input(INPUT_POST, 'FEV PREV');
                    $fevReal = filter_input(INPUT_POST, 'FEV REAL');
                    $marPrev = filter_input(INPUT_POST, 'MAR PREV');
                    $marReal = filter_input(INPUT_POST, 'MAR REAL');
                    $abrPrev = filter_input(INPUT_POST, 'ABR PREV');
                    $abrReal = filter_input(INPUT_POST, 'ABR REAL');
                    $maiPrev = filter_input(INPUT_POST, 'MAI PREV');
                    $maiReal = filter_input(INPUT_POST, 'MAI REAL');
                    $junReal = filter_input(INPUT_POST, 'JUN PREV');
                    $junReal = filter_input(INPUT_POST, 'JUN REAL');
                    $julPrev = filter_input(INPUT_POST, 'JUL PREV');
                    $julReal = filter_input(INPUT_POST, 'JUL REAL');
                    $agoPrev = filter_input(INPUT_POST, 'AGO PREV');
                    $agoReal = filter_input(INPUT_POST, 'AGO REAL');
                    $setPrev = filter_input(INPUT_POST, 'SET PREV');
                    $setReal = filter_input(INPUT_POST, 'SET REAL');
                    $outPrev = filter_input(INPUT_POST, 'OUT PREV');
                    $outReal = filter_input(INPUT_POST, 'OUT REAL');
                    $novPrev = filter_input(INPUT_POST, 'NOV PREV');
                    $novReal = filter_input(INPUT_POST, 'NOV REAL');
                    $dezPrev = filter_input(INPUT_POST, 'DEZ PREV');
                    $dezReal = filter_input(INPUT_POST, 'DEZ REAL');
                    $id = filter_input(INPUT_POST, 'ID');
                ?>
                    <form method="post" action="update-qualite.php">
                        <input name="ID" type="hidden" id="ID" value="<? echo $id; ?>">
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>KPI</label>
                            <input type="text" class="form-control" id="KPI" name="KPI" value="<?php echo $kpi; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>PILOTE</label>
                            <input type="text" class="form-control" id="PILOTE" name="PILOTE" value="<?php echo $pilote; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>JANEIRO PREVISTO</label>
                            <input type="text" class="form-control" id="JAN PREV" name="JAN PREV" value="<?php echo $janPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>JANEIRO REALIZADO</label>
                            <input type="text" class="form-control" id="JAN REAL" name="JAN REAL" value="<?php echo $janReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>FEVEREIRO PREVISTO</label>
                            <input type="text" class="form-control" id="FEV PREV" name="FEV PREV" value="<?php echo $fevPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>FEVEREIRO REALIZADO</label>
                            <input type="text" class="form-control" id="FEV REAL" name="FEV REAL" value="<?php echo $fevReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>MARÇO PREVISTO</label>
                            <input type="text" class="form-control" id="MAR PREV" name="MAR PREV" value="<?php echo $marPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>MARÇO REALIZADO</label>
                            <input type="text" class="form-control" id="MAR REAL" name="MAR REAL" value="<?php echo $marReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>ABRIL PREVISTO</label>
                            <input type="text" class="form-control" id="ABR PREV" name="ABR PREV" value="<?php echo $abrPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>ABRIL REALIZADO</label>
                            <input type="text" class="form-control" id="ABR REAL" name="ABR REAL" value="<?php echo $abrReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>MAIO PREVISTO</label>
                            <input type="text" class="form-control" id="MAI PREV" name="MAI PREV" value="<?php echo $maiPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>MAIO REALIZADO</label>
                            <input type="text" class="form-control" id="MAI REAL" name="MAI REAL" value="<?php echo $maiReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>JUNHO PREVISTO</label>
                            <input type="text" class="form-control" id="JUN PREV" name="JUN PREV" value="<?php echo $junPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>JUNHO REALIZADO</label>
                            <input type="text" class="form-control" id="JUN REAL" name="JUN REAL" value="<?php echo $junReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>JULHO PREVISTO</label>
                            <input type="text" class="form-control" id="JUL PREV" name="JUL PREV" value="<?php echo $julPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>JULHO REALIZADO</label>
                            <input type="text" class="form-control" id="JUL REAL" name="JUL REAL" value="<?php echo $julReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>AGOSTO PREVISTO</label>
                            <input type="text" class="form-control" id="AGO PREV" name="AGO PREV" value="<?php echo $agoPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>AGOSTO REALIZADO</label>
                            <input type="text" class="form-control" id="AGO REAL" name="AGO REAL" value="<?php echo $agoReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>SETEMBRO PREVISTO</label>
                            <input type="text" class="form-control" id="SET PREV" name="SET PREV" value="<?php echo $setPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>SETEMBRO REALIZADO</label>
                            <input type="text" class="form-control" id="SET REAL" name="SET REAL" value="<?php echo $setReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>OUTUBRO PREVISTO</label>
                            <input type="text" class="form-control" id="OUT PREV" name="OUT PREV" value="<?php echo $outPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>OUTUBRO REALIZADO</label>
                            <input type="text" class="form-control" id="OUT REAL" name="OUT REAL" value="<?php echo $outReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>NOVEMBRO PREVISTO</label>
                            <input type="text" class="form-control" id="NOV PREV" name="NOV PREV" value="<?php echo $novPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>NOVEMBRO REALIZADO</label>
                            <input type="text" class="form-control" id="NOV REAL" name="NOV REAL" value="<?php echo $novReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>DEZEMBRO PREVISTO</label>
                            <input type="text" class="form-control" id="DEZ PREV" name="DEZ PREV" value="<?php echo $dezPrev; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <label>DEZEMBRO REALIZADO</label>
                            <input type="text" class="form-control" id="DEZ REAL" name="DEZ REAL" value="<?php echo $dezReal; ?>">
                        </div>
                        <div class="form-group col-lg-4" style="padding-left: 0px;">
                            <button type="submit" class="btn-theme btn-theme-sm btn-base-bg text-uppercase">Salvar</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

UPDATE-QUALITE.PHP

<!--Update de edição-->
<?php

    $kpi = filter_input(INPUT_POST, 'KPI');
    $pilote = filter_input(INPUT_POST, 'PILOTE');
    $janPrev = filter_input(INPUT_POST, 'JAN PREV');
    $janReal = filter_input(INPUT_POST, 'JAN REAL');
    $fevPrev = filter_input(INPUT_POST, 'FEV PREV');
    $fevReal = filter_input(INPUT_POST, 'FEV REAL');
    $marPrev = filter_input(INPUT_POST, 'MAR PREV');
    $marReal = filter_input(INPUT_POST, 'MAR REAL');
    $abrPrev = filter_input(INPUT_POST, 'ABR PREV');
    $abrReal = filter_input(INPUT_POST, 'ABR REAL');
    $maiPrev = filter_input(INPUT_POST, 'MAI PREV');
    $maiReal = filter_input(INPUT_POST, 'MAI REAL');
    $junReal = filter_input(INPUT_POST, 'JUN PREV');
    $junReal = filter_input(INPUT_POST, 'JUN REAL');
    $julPrev = filter_input(INPUT_POST, 'JUL PREV');
    $julReal = filter_input(INPUT_POST, 'JUL REAL');
    $agoPrev = filter_input(INPUT_POST, 'AGO PREV');
    $agoReal = filter_input(INPUT_POST, 'AGO REAL');
    $setPrev = filter_input(INPUT_POST, 'SET PREV');
    $setReal = filter_input(INPUT_POST, 'SET REAL');
    $outPrev = filter_input(INPUT_POST, 'OUT PREV');
    $outReal = filter_input(INPUT_POST, 'OUT REAL');
    $novPrev = filter_input(INPUT_POST, 'NOV PREV');
    $novReal = filter_input(INPUT_POST, 'NOV REAL');
    $dezPrev = filter_input(INPUT_POST, 'DEZ PREV');
    $dezReal = filter_input(INPUT_POST, 'DEZ REAL');
    $id = filter_input(INPUT_POST, 'ID');

    $strcon = mysqli_connect('localhost', 'root', '', 'banco') or die('Erro ao conectar ao banco de dados');
    $sql = "UPDATE  'banco'.'qualite' SET 'KPI' = '$kpi', 'PILOTE' = '$pilote', 'JAN PREV' = '$janPrev', 'JAN REAL' = '$janReal', 'FEV PREV' = '$fevPrev', 'FEV REAL' = '$fevReal', 'MAR PREV' = '$marPrev', 'MAR REAL' = '$marReal', 'ABR PREV' = '$abrPrev', 'ABR REAL' = '$abrReal', 'MAI PREV' = '$maiPrev', 'MAI REAL' = '$maiReal', 'JUN PREV' = '$junPrev',
    'JUN REAL' = '$junReal', 'JUL PREV' = '$julPrev', 'JUL REAL' = '$julReal', 'AGO PREV' = '$agoPrev', 'AGO REAL' = '$agoReal', 'SET PREV' = '$setPrev', 'SET REAL' = '$setReal', 'OUT PREV' = '$outPrev', 'OUT REAL' = '$outReal', 'NOV PREV' = '$novPrev', 'NOV REAL' = '$novReal', 'DEZ PREV' = '$dezPrev', 'DEZ REAL' = '$dezReal' WHERE  'qualite'.'ID' = '$id'";

    mysqli_query($strcon,$sql) or die("Erro ao tentar atualizar registro. " . mysqli_error($strcon));
    mysqli_close($strcon);

    var_dump($sql);


?>

But when I give this var_dump (), the following result appears:

What I was already saved in the bank is the variable I'm getting, but what I'm trying to change is not getting.

EDIT: I COLLECTED A HIDDEN FILE WITH THE ID AT THE BEGINNING OF THE FORM AND NOW IT TAKES THE ID, BUT THE REST IS NOT YET.

Does anyone have any idea what might be causing this?

    
asked by anonymous 25.05.2018 / 15:36

1 answer

1

When a name of some form element contains space, and the form is submitted, the page that will retrieve the value of that element replaces the space with an underscore (_), also known as a dash, underline, or dash lower or lower line. Therefore when retrieving the values of the submitted fields replace the space with a underline

Example:

no formulario <input name="JAN PREV" .....

para recuperar o valor desse input '$janPrev = filter_input(INPUT_POST, 'JAN_PREV');'

If you run something like

<form method="post" action="">
    <input type="text" id="JAN PREV" name="JAN PREV" value="xxx">
    <input type="text" id="JAN REAL" name="JAN REAL" value="zzz">
    <button type="submit" name="submit">Salvar</button>
</form>

<?php
if(isset($_POST['submit'])){

    foreach ($_POST as $name => $value) {
       echo $name." ". $value;
       echo "<br>";
    }
}
?>

The result will be

JAN_PREV xxx
JAN_REAL zzz

Notes

You are overwriting the variable $junReal instead of creating 2 variables $junPrev and $junReal

..............
$junReal = filter_input(INPUT_POST, 'JUN PREV');
$junReal = filter_input(INPUT_POST, 'JUN REAL');
..............

Correction:

..............
$junPrev = filter_input(INPUT_POST, 'JUN PREV');
$junReal = filter_input(INPUT_POST, 'JUN REAL');
..............
  

no update has WHERE qualite . ID = '$id' Only in the form is not passing the value $ id

  • Your form is not bringing your bank data to the inputs.
  • Your SELECT $query = mysqli_query($lnk, "SELECT PILOTE FROM qualite"); is only bringing the value of the PILOTE field

    Coloque um * ou o nome das colunas necessárias 
    
  • These lines

      $kpi = filter_input(INPUT_POST, 'KPI'); 
      $pilote = filter_input(INPUT_POST, 'PILOTE');
      ............................................
      etc.....' 
    

    They are useless on the form page

  •   

    To bring bank data

     $query = mysqli_query($lnk, "SELECT * FROM qualite");
    
        while($row = mysqli_fetch_assoc($query)) {
    
            $kpi = $row["KPI"];
            $pilote = $row["PILOTE"];
            $janPrev = $row["JAN PREV"];
            $janReal = $row["JAN REAL"];
            ...........................
            ...........................
    
        }
    
        
    04.06.2018 / 14:57