Unsupported update form

0

I have a form already filled with two extra inputs only for the user to edit the information already registered and add the two new ones.

However, although%% of "saved successfully" appears, when I check with the bank, the information has not changed or added information.

My form:

<?php
    require 'strcon.php';
    $query = mysqli_query($strcon, "SELECT SERVICO FROM pedidos");
    $cliente = filter_input(INPUT_POST, 'CLIENTE');
    $servico = filter_input(INPUT_POST, 'SERVICO');
    $solicitacao = filter_input(INPUT_POST, 'SOLICITACAO');
    $previsao = filter_input(INPUT_POST, 'PREVISAO');
    $valor = filter_input(INPUT_POST, 'VALOR');
    $acerto = filter_input(INPUT_POST, 'ACERTO');
    $saldo = filter_input(INPUT_POST, 'SALDO');
    $id = filter_input(INPUT_POST, 'ID');
?>

    <!-- formulário -->
    <form method="POST" action="update-edi.php">
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-md-10 mx-auto">
          <div class="form-group">
            <label for="CLIENTE">Cliente:</label>
            <input type="text" class="form-control" id="CLIENTE" name="CLIENTE" value="<?php echo $cliente; ?>">
          </div>
          <div class="form-group">
            <label for="SERVICO">Serviço:</label>
            <input type="text" class="form-control" id="SERVICO" name="SERVICO" value="<?php echo $servico; ?>">
          </div>
          <div class="form-group">
            <label for="SOLICITACAO">Data de solicitação:</label>
            <input type="text" class="form-control" id="SOLICITACAO" name="SOLICITACAO" value="<?php echo $solicitacao; ?>">
          </div>
          <div class="form-group">
            <label for="PREVISAO">Data prevista:</label>
            <input type="text" class="form-control" id="PREVISAO" name="PREVISAO" value="<?php echo $previsao; ?>">
          </div>
          <div class="form-group">
            <label for="VALOR">Valor:</label>
            <input type="text" class="form-control" id="VALOR" name="VALOR" value="<?php echo $valor; ?>">
          </div>
          <div class="form-group">
            <label for="ACERTO">Acerto:</label>
            <input type="text" class="form-control" id="ACERTO" name="ACERTO" value="<?php echo $acerto; ?>">
          </div>
          <div class="form-group">
            <label for="SALDO">Saldo:</label>
            <select type="text" class="form-control" id="SALDO" name="SALDO" value="<?php echo $saldo; ?>">
              <option> Selecione... </option>
              <option> Positivo </option>
              <option> Negativo </option>
              <option> Neutro </option>
            </select>
          </div>
          <button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
        </div>
      </div>
    </div>
    </form>

My update page:

<?php

    $acerto = filter_input(INPUT_POST, 'ACERTO');
    $saldo = filter_input(INPUT_POST, 'SALDO');
    $id = filter_input(INPUT_POST, 'ID');

    $strcon = mysqli_connect('localhost', 'root', '', 'sis_tam') or die('Erro ao conectar ao banco de dados');
    $sql = 'UPDATE pedidos SET ACERTO = " '. $acerto . ' ",  SALDO = " '. $saldo . ' "  WHERE 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>';

    var_dump($acerto, $saldo, $id);

?>

I do not understand why you are not saving, if someone understands, I thank you. :)

    
asked by anonymous 25.01.2018 / 17:42

2 answers

1

It turns out that nothing is found in your WHERE , you have to remove the extra spaces in query :

$sql = 'UPDATE pedidos SET ACERTO = "'. $acerto . '",  SALDO = "'. $saldo . '"  WHERE ID = "'. $id . '" ';

You were comparing 5 with 5 for example if id was equal to 5 .

    
25.01.2018 / 17:48
0

On the update page you are retrieving a $id = filter_input(INPUT_POST, 'ID'); ID that was not passed by the form.

Add on the form page a input that can be hidden or text or number:

      <div class="form-group">
        <label for="id">ID:</label>
        <input type="hidden" class="form-control" id="ID" name="ID" value="<?php echo $id; ?>">
      </div>
  

As for spaces in the UPDATE statement what will occur is:

  • Values with spaces will be inserted in the columns.
  • In the WHERE condition: numeric conversion ignores spaces. It would not work if it were other characters. If the field is char, then that's a problem.
  •   

    So if the ID is numeric then the query will be successful.

        
    17.08.2018 / 15:45