Input fields are not being filled according to the value

0

On my system there is a page with a form that registers an order and another page with a table that shows all the records of registered orders.

In each row of the table has a request and an edit button that opens a form equal to that used in the order form that should be filled with the information registered.

This is the edit button:

// Adicionando botão de exclusão
    $table .= '<td><form action="FormEdicao.php" method="post">'; 
    $table .= '<input type="hidden" name="ID" value="'.$r['ID'].'">';
    $table .= '<input type="hidden" name="CLIENTE" value="'.$r['CLIENTE'].'">';
    $table .= '<input type="hidden" name="SERVICO" value="'.$r['SERVICO'].'">';
    $table .= '<input type="hidden" name="SOLICITACAO" value="'.$r['SOLICITACAO'].'">';
    $table .= '<input type="hidden" name="PREVISAO" value="'.$r['PREVISAO'].'">';
    $table .= '<input type="hidden" name="VALOR" value="'.$r['VALOR'].'">';
    $table .= '<button class="btn btn-primary"><i class="glyphicon glyphicon-pencil"> Editar </i></button>'; //aqui está o seu botão
    $table .= '</form></td>';
}

This is the editing 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, 'PREVISAO');
    $valor = filter_input(INPUT_POST, 'VALOR');
    $id = filter_input(INPUT_POST, 'ID');
?>

    <!-- formulário de edição -->
    <form method="POST" action="update-ped.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>
          <button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
        </div>
      </div>
    </div>
    </form>

But for some reason these fields that should be filled are not, follow the images to facilitate:

    
asked by anonymous 24.01.2018 / 17:37

2 answers

1

Hello; save and edit follow somewhat different logics; try this, briefly:

1 - Your table must have a primary key column (let's call it id);

2 - You need to pass this id for the selected record  usually by the GET method and you should declare a variable referring to this id; ex:

$id=$_GET['id'];

(search for querystrings );

3 - your database query should use this id with the where clause ex:

$consulta=select * from tabela where id=$id;

4- Your $ query variable should be a mysqli_query command; ex:

mysqli->query($strcon,"SELECT * FROM tabela where id=$id");

5 - Retrieve records using fetch

while($row = $consulta->fetch_array()){

6 - display the column within the "value" of the form; ex:

input type="text" class="form-control" id="SOLICITACAO" name="SOLICITACAO" value="<?php echo $row['solicitacao']; ?>">

7 - ex of the button:

<input type="button" onclick="javascript: location.href='detalhes_noticia.php?id=<?php
echo $lista1->id?>';" value="Clique Aqui" />
    
24.01.2018 / 19:00
1

Based on this information, you can not give a definitive answer, but what I can do to help you is to understand what is happening to take action.

We need to know if the query data that is in the form where you have the "Edit" button is being sent via POST to that other page.

To do this right click on the "Edit" button and click "inspect". It will open another browser window which are the developer tools, in this window at the top has a button called "Network" and there you leave checked the "Preserve log" option.

Note: If this Developer Tools window "opens in the same window you are using, you can open it separately as shown in the figure below:

Nowwhenyouclickthe"Edit" button on the site page through this "Network" tab you can see the information on the right side of the request including the data sent via POST, see an example in the figure below: p>

These tips to use the Tool for developers I exemplified using Google Chrome, also exists in other browsers but may have a name or way to enter a little different, if you use another is just give one searched.

Another practical thing to try to understand the problem is to echo the variables that receive the values via POST to see if they are coming empty.

Hope you can help!

See you soon!

    
24.01.2018 / 19:18