Update does not find what was typed in the inputs

Asked

Viewed 45 times

1

I have a system where you can change the information of a record through an editing form, only 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);


?>

Only when I give this var_dump(), the following result appears: inserir a descrição da imagem aqui

What was already saved in the bank the variable is even receiving, but what I’m trying to change is not receiving.

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

Does anyone have any idea what might be causing this?

  • 1

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

  • So, I created a Hidden field for the ID at the beginning of the form and now it recognizes the ID, but the rest not yet.

1 answer

1

When a name of some element of the form contains space, and the form is submitted, the page that will recover the value of that element replaces the space by an underscore (_), also known as a bottom dash, underline or bottom dash or low line. So when recovering 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


Remarks

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 WHEREqualite.ID= '$id' Only on the form is not passing the value $id

  1. Your form is not bringing the database data to input.
  2. YOUR SELECT $query = mysqli_query($lnk, "SELECT PILOTE FROM qualite"); is only bringing the value of the field PILOTE

    Coloque um * ou o nome das colunas necessárias 
    
  3. Those lines

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

    No use on the form page

To bring data from the bank

 $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"];
        ...........................
        ...........................

    }
  • Thanks for the correction. I edited here but it’s still giving the same problem. :/

  • So I put a Hidden field in the form with the ID. I’ll edit it up there

  • 1

    https://ideone.com/SnpVgd

  • I don’t understand why yours is working perfect and mine isn’t. I even paste your $sql here and it’s not working. :/

  • It’s weird because he gets to take the things that were already saved in the bank, which in this case are KPI and PILOTE, but the rest not.

  • What you changed to work code?

  • I just put _ and it worked. Thank you. Comments with reply for me to give as answered.

Show 2 more comments

Browser other questions tagged

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