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

Asked

Viewed 68 times

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 could I recover the data entered by the user, and launch it in this same form ? For example, the user makes the registration, this data goes to the database, and then I have an administrator page where are presented all registered users (up to ai blz), so for each user I would have the options to delete, edit, and when you click edit the screen shown is 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...

1 answer

1


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

Example: On the.php data page you will receive by 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>

Browser other questions tagged

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