How to edit registered data so that when selecting the register to be changed, the data of the same appear in the same form that was created?

0

Given the following form:

<form action="action_page.php">
  <fieldset>
    <legend>Personal information:</legend>
    First name:<br>
    <input type="text" name="firstname" value="Mickey"><br>
    Last name:<br>
    <input type="text" name="lastname" value="Mouse"><br><br>
    Senha:<br>
    <input type="password" name="senha" value="Senha"><br><br>
    <input type="submit" value="Submit">
  </fieldset>
</form>

How can I recover the data entered by the user, and post it on this same form? For example, the user does the registration, this data goes to the database, and then I own an admin page where all the registered users are presented (up to ai blz), so for each user I would have the options to delete, edit, being that when clicking on edit the displayed screen is the one of the form above but with the user data to be changed? It's like a CRUD (I think) only I'm kind of (not to say totally) lost ...

    
asked by anonymous 16.05.2016 / 22:31

1 answer

1

Use a call to define the function (if it will be Edit, Insert, etc). Let's simulate it for $ _GET.

Example: On the data.php page you will receive the URL

    dados.php?funcao=Editar&id=2


    if($_GET['funcao'] == "Editar"){
    // Aqui tu faz a chamada do banco de dados usando o ID que também veio pelo GET (pode ser da forma que quiseres)

    Com as variáveis já definidas pelo BD é só mudar os values dos inputs.

<form action="action_page.php">
  <fieldset>
    <legend>Personal information:</legend>
    First name:<br>
    <input type="text" name="firstname" value="<?php echo $linha['campo_tabela_first_name'];?>"><br>
    Last name:<br>
    <input type="text" name="lastname" value="<?php echo $linha['campo_tabela_last_name'];?>"><br><br>
    Senha:<br>
    <input type="password" name="senha" value="Senha"><br><br>
    <input type="submit" value="Submit">
  </fieldset>
</form>
    
16.05.2016 / 23:42