0
Good morning, I have a question about how to make the above inputs receive data from my database, for example: let’s assume that I will change something, but I just want to change a value the cep(just an example) but to change I need to know all the other values not to leave them blank, ie I want when I click update the table is populated with the old values making me only have to edit :D
<form action="editar.php" method="POST">
<table class="table table-striped">
<thead>
<tr>
<th>Cpf Novo</th>
<th>Nome Novo</th>
<th>Cep Novo</th>
<th>Rua Novo</th>
<th>Bairro Novo</th>
<th>Cidade Novo</th>
<th>Estado Novo</th>
<th>Ibge Novo</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" onclick="" class="form-control input-sm" id="cpf" name="cpf" required><br></td>
<td><input type="text" class="form-control input-sm" name="nom" required><br></td>
<td><input type="text" class="form-control input-sm" id="cep" name="end" required><br></td>
<td><input name="rua" class="form-control input-sm" type="text" id="rua" required /><br></td>
<td><input name="bairro" class="form-control input-sm" type="text" id="bairro" required/><br></td>
<td><input name="cidade" class="form-control input-sm" type="text" id="cidade" required/><br></td>
<td><input name="uf" class="form-control input-sm" type="text" id="uf" required/><br></td>
<td><input name="ibge" class="form-control input-sm" type="text" id="ibge" required/><br></td>
</tr>
</tbody>
</table>
<br><input type="submit" class="btn btn-default"><input type="button" class="btn btn-warning" value="Voltar"
onclick="window.location='/Banco_de_dados/index.php';" />
</form>
</body>
</html>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "meubd";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT nome, cpf, cep, rua, bairro, cidade, estado, ibge FROM pessoas";
$result = $conn->query($sql);
?>
<div>
<table class="table table-striped" id="myTable">
<thead>
<tr>
<th>CPF</th>
<th>Nome</th>
<th>Cidade</th>
<th>estado</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($result)){
?>
<tr>
<td><?=$row['cpf']?></td>
<td><?=$row['nome']?></td>
<td><?=$row['cidade']?></td>
<td><?=$row['estado']?></td>
<td><input type="button" class="btn btn-danger" value="Delete"
onclick="window.location='/Banco_de_dados/delete.html';" /></td>
<td><input type="button" class="btn btn-primary" value="Update"
onclick="window.location='/Banco_de_dados/editar.html';" /></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
For that you will need ajax
– Daniel Costa
What is the input page to edit? You can simply send parameters via get
– Miguel
I just put up the inputs that should receive the values
– Nikk 17016
tries to edit your question and just leave the code you really need for what you need, with all the code gets a little complicated
– Marcelo Diniz
Ready changed, only the important parts now.
– Nikk 17016
You can better organize the question by adding what the code just above it is about?
– user28595
I don’t know if I understand it better, but what I want is your help to pass the values from my database to the inputs when I click update :D
– Nikk 17016
I suggest you know the plugin for jQuery to deal with grids: Datatables. It’s free, well-documented, and it will help you resolve this situation. I see other problems in your code, but if you use this plugin will of course fix them.
– Thiago Lunardi
Yes I have a good knowledge about jquery, but I always mess up and I don’t know which command to use, could you help me? or at least tell me what to do, if you have any site that teaches what needs to be done can also pass me, thanks to all have been of great help so far :D!!!
– Nikk 17016
What about the mistakes commented can you point them out to me? is that I’m in a bit of a hurry
– Nikk 17016