Input fields are not being filled in according to value

Asked

Viewed 374 times

0

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

Each row of the table has a request and an edit button that opens a form equal to the one used in the application registration that should be filled with the registered information.

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 images to facilitate:

inserir a descrição da imagem aquiinserir a descrição da imagem aqui

  • As this your edit button?

  • My edit button is a normal href that redirects to the edit page.

  • I’ll put my edit button on the question.

  • Dude, the problem was the edit button, the Naames were wrong, you were right.

2 answers

1

ola; save and edit follow somewhat different logics; try so, briefly:

1 - your table must have a primary key column (Let’s call it id);

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

$id=$_GET['id'];

(research on querystrings);

3 - your query to the database should use that id with the Where clause ex:

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

4-its variable $query must be a command mysqli_query; ex:

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

5- retrieve records using fetch

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

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

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

7 - former of the boot:

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

1

Based on this information there is no way to give a definitive answer, but what I can help you to understand is what is taking place to take action.

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

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

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

inserir a descrição da imagem aqui

Now when you click on the "Edit" button on the page of the site through this "Network" tab you can see in the right pane the information of the request including the data sent via POST, see an example in the figure below:

inserir a descrição da imagem aqui

These tips to use the Developer Tool I exemplified using Google Chrome, also exists in other browsers but maybe you have a name or way to enter a little different, if you use another just give a search.

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

I hope it helps you!

See you around!

Browser other questions tagged

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