2
This is a CRUD in php where the only option missing is the editing of a register, it happens that I intend to use the same form
The problem is that when I click edit the fields of value
inputs remain empty which is the value I set by default. Let’s go to code:
Inputs from the page above:
<input type="text" name="nome" class="form-control" value="<?php echo $nome?>" maxlength="70">
<input type="password" name="senha" class="form-control" value="<?php echo $senha?>" maxlength="25">
Edit button link: (NOTE: your file is not in quotes because everything is already being treated as a string)
<a class='btn btn-info' href='processaDados.php?editar=$row[idusuario]'>Editar</a>
Code of the processed fileDados.php that is already executed at the time the page is loaded:
session_start();
$conn = new PDO("mysql:dbname=db_CRUD;host=localhost", "root", "");
$nome = '';
$senha = '';
Code of the processed fileDados.php that runs when the Edit button is triggered:
if (isset($_GET['editar'])) {
$stmt = $conn->prepare("SELECT * FROM tb_dados WHERE idusuario = :ID");
$stmt->bindParam(":ID", $id);
$id = (int) $_GET['editar'];
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$nome = $results[0]["desnome"];
$senha = $results[0]["dessenha"];
header("location: index.php");
}
I only put the main parts of the code to be simplified and because I know that the problem is in this section above. It is worth noting that I have already tested the last code outside the if
and print the amounts received on processaDados.php
(I removed the header("location: index.php
");), I mean, I’m getting the name and password when I click edit, but the problem is when I try to assign these values to values
of inputs.