Record edit form does not change

Asked

Viewed 50 times

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 page only that already filled with the information just for you to change.

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

This is my editing 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?

  • Comments all "echo script" that and tries to print your $sql on screen and test it in hand.

  • string(84) "UPDATE sis_tam.materiais SET QUANTIDADE = '3' WHERE materiais.ID = '' " `Looks like he’s not getting the ID

  • tries to print this $id from above, if you don’t take a look at the previous page

1 answer

0


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

and also give a studied in design Patterns, code quality these things... Because I don’t know what level you are at, but the quality of this code is very precarious: coupled bank, multi responsibility, data access in view...

  • Friend, my level is "I signed up for a Jango position and I got stuck in a php".

  • Puts :/ is.. these tramp traps are fodas good if you want to take a look afterwards: http://pokephp.com.br/ and tbm the lack of PHPSP, you are most welcome :) https://phpsp-slackin.jelasticlw.com.br/

Browser other questions tagged

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