I have a simple form that stores info into a database (index.html) and a script to show its results (show.php) which is just a query executed with a while statement to I can generate rows of results for a table.
I added two images in one of the columnos for edition and printing, but I don't have any idea on how to bring the results of that specific row back to index.html for edition/updating the info. I want to populate that form so I can continue working over the updating form.
I'll paste just the code where I do the while statement:
while ($colum = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td><h6> <img src='editar.png'> <span hidden style='background:moccasin'>". $colum['id']."</span> </img> <img src='impresora.png'></img></td></h6>";
echo "<td><h6>" . $colum['nombre']. "</td></h6>";
echo "<td><h6>" . $colum['apellido_paterno']. "</td></h6>";
echo "<td><h6>" . $colum['apellido_materno']. "</td></h6>";
echo "<td><h6>" . $colum['grupo']. "</td></h6>";
echo "<td><h6>" . $colum['tutor']. "</td></h6>";
echo "<td><h6>" . $colum['domicilio']. "</td></h6>";
echo "<td><h6>" . $colum['telefono1']. "</td></h6>";
echo "<td><h6>" . $colum['telefono2']. "</td></h6>";
echo "<td><h6>" . $colum['nee']. "</td></h6>";
echo "<td><h6>" . $colum['discapacidad']. "</td></h6>";
echo "<td><h6>" . $colum['leer']. "</td></h6>";
echo "<td><h6>" . $colum['escribir']. "</td></h6>";
echo "<td><h6>" . $colum['historial']. "</td></h6>";
echo "<td><h6>" . $colum['enfermedad']. "</td></h6>";
echo "<td><h6>" . $colum['medicamento']. "</td></h6>";
echo "</tr>";
}
So, each one of those echos belong to each one of the inputs I want to populate back in the form (they have the exact same name). Also, it might sound silly but I want the simplest possible solution, since this is not for any company, just for personal use so I could put security aside on this.
Thanks in advance for your help.
Edit 1: I tried using the URL format to fill the inputs but doesn't work like this:
index.php?nombre=JustAName
These is an example of how my inputs look in index.php:
<form action="registrar2.php" method="post" class="needs-validation" name="procesar" novalidate onsubmit="return validarform()">
<div class="row">
<div class="col-sm-6 col-md-12 col-xs-12">
<div class="form-group mb-2">
<div class="input-group">
<span class="input-group-text">Nombre del Alumno:</span>
<input type="text" aria-label="First name" id="nombre" name="nombre" class="form-control" required>
<div class="invalid-feedback">Ingresar nombre.
</div>
</div>
</div>
</div>
<!-- SOME OTHER INPUTS ARE BELOW TOO -->
</form>
My Answer:
"
echo "
echo "
echo "
echo "
![](edit.png)
echo "
![](print.png)
echo "
}
In the code above, I added two links in the table row for editing and printing. The links pass the id of the row to edit.php and print.php respectively. In edit.php, you can retrieve the row data based on the id and populate the form for editing.
Here's an example of how you can populate the form in index.html for editing:
index.html:
edit.php:
$id = $_GET['id'];
$query = "SELECT * FROM table_name WHERE id = $id";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result);
echo "";
In edit.php, you retrieve the row data based on the id passed from the link and use JavaScript to populate the form fields in index.html with the retrieved data. This way, when the form is loaded, it will already have the data from the selected row for editing.
Rate this post
5 of 5 based on 9591 votesComments