Record editing form does not change

1

On one page I have a material registration form, in another I have a table that shows all the materials registered with a button to change the information about a material and this button opens a third page with the same form of the first one only page that already filled with the information just for you to change.

But when I change the information and click to save, the saved script appears and it does not change the information.

This is my edit form:

<?php
    require 'strcon.php';
    $query = mysqli_query($strcon, "SELECT MATERIAL FROM materiais");
    $material = filter_input(INPUT_POST, 'MATERIAL');
    $quantidade = filter_input(INPUT_POST, 'QUANTIDADE');
    $id = filter_input(INPUT_POST, 'ID');
?>

    <!-- formulário -->
    <form method="POST" action="update-est.php">
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-md-10 mx-auto">
            <div class="form-group">
               <label for="MATERIAL">Material:</label>
               <input type="text" class="form-control" id="MATERIAL" name="MATERIAL" value="<?php echo $material; ?>">
            </div>
            <div class="form-group">
               <label for="QUANTIDADE">Quantidade:</label>
               <input type="text" class="form-control" id="QUANTIDADE" name="QUANTIDADE" value="<?php echo $quantidade;?>">
            </div>
            <button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
        </div>
      </div>
    </div>
    </form>

    <hr>

And this is my update:

<!--Update Estoque-->
<?php

    $quantidade = filter_input(INPUT_POST, 'QUANTIDADE');
    $id = filter_input(INPUT_POST, 'ID');

    $strcon = mysqli_connect('localhost', 'root', '', 'sis_tam') or die('Erro ao conectar ao banco de dados');
    $sql = "UPDATE  'sis_tam'.'materiais' SET  'QUANTIDADE' =  '$quantidade' WHERE  'materiais'.'ID' = '$id' ";
    mysqli_query($strcon,$sql) or die("Erro ao tentar atualizar registro. " . mysqli_error($strcon));
    mysqli_close($strcon);

    echo '<script type="text/javascript">
                alert("Salvo com Sucesso !");
                window.history.go(-1);
            </script>';


?>

Can anyone identify why this is happening?

    
asked by anonymous 30.01.2018 / 14:00

1 answer

0

You are not sending your id on the form, it must be in a <input type="hidden" .../>

And also give a studied in design patterns, quality of code these things ... Because I do not know at what level you are, but the quality of this code is very precarious: coupled bank, multi responsibility, data access in the view ...

    
30.01.2018 / 14:30