Edit selected record

Asked

Viewed 341 times

1

I show records coming from the database in td’s, in each record there is an edit button that opens the edit screen, however I do not know how to display on this screen the data of the registry I clicked, to edit and save.

  • Post what you’ve tried (source code), you can catch the id of the selected information?

  • I haven’t tried anything yet, I don’t know how I can do it. And I can select the id.

  • Maybe this will help http://blogwebdesignmicrocamp.com.br/programcao/ph-instrucao-update-como-editar-registros/

  • simply, in the edit link you can get <a href='edit.php? id=$code recovered'>Edit</a>

  • @R.Santos, this helped yes. After finishing, enter the code I got.

2 answers

0


From this website indicated by @R.Santos, I followed the steps and arrived at the following code:

dados.php //(tela que exibe os registros do banco)

echo '<a href="edicao.php?id=' . $id . '"><button class="btn btn-default btn-xs"><i class="fa fa-pencil"></i></button></a>';

In this data screen I capture the registry id via the button.

    edicao.php //(tela onde a o formulário de edição)

    <?php
    $id = $_GET['id'];
    $conexao = mysqli_connect('', '', '', '');

    <form class="form-horizontal tasi-form" method="POST" action="php/editar.php">

    <input type="text" class="form-control" name="nome" required="required" value="<?php echo $exibe['nome'] ?>">  
    ?>

On the edit screen I get this id that was passed by the url and start the connection, after, I adjust the form that calls the edit file and organize the database fields in the form fields.

    editar.php //(update nos campos)

    $id = $_POST['id'];

    $conexao = mysqli_connect('', '', '', '');

    $result  = mysqli_query($conexao, "UPDATE pessoas SET id = '$id'

    mysqli_close($conexao);

Finally, I update the edited fields. For more details just go to site that has everything well explained.

0

On the button there should be an indicative of which record you want to edit. For example: In record 1 on the button link you should have something like (href="my-table/edit.php? id=$id-do-record")

Browser other questions tagged

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