CRUD Mysql , I need a button that fills inputs

Asked

Viewed 370 times

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è assim que está meu site agora e aqueles são os botões que vão me levar a tabela de delete e update

		
			<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

  • What is the input page to edit? You can simply send parameters via get

  • I just put up the inputs that should receive the values

  • 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

  • Ready changed, only the important parts now.

  • You can better organize the question by adding what the code just above it is about?

  • 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

  • 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.

  • 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!!!

  • What about the mistakes commented can you point them out to me? is that I’m in a bit of a hurry

Show 5 more comments
No answers

Browser other questions tagged

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