-1
I am trying to create an option to edit the information of a table I created using PHP and Mysql, I even managed to create the option and the data can be modified, the only problem is that if I click the button "edit" in a table row, the editing screen always displays all the lines, ie, shows all the data instead of showing only what I want to edit, how do I resolve this?
this is the code I created:
<?php
ini_set('default_charset','UTF-8');
$host="localhost";
$username="********";
$password="********";
$db_name="*********";
$con=mysqli_connect("$host", "$username", "$password", "$db_name")or die("cannot connect");
mysqli_set_charset($con,"utf8");
$sql = "SELECT `ID`, `carro`, `datasaida` , `horasaida` , `datachegada`, `horachegada`, `kminicial`, `kmfinal`, `destino`, `motorista` FROM `carro`";
$query = $con->query($sql);
while ($dados = $query->fetch_assoc()) {
$id = $dados["ID"];
$carro = $dados["carro"];
$datasaida = $dados["datasaida"];
$horasaida = $dados["horasaida"];
$datachegada = $dados["datachegada"];
$horachegada = $dados["horachegada"];
$kminicial = $dados["kminicial"];
$kmfinal = $dados["kmfinal"];
$destino = $dados["destino"];
$motorista = $dados["motorista"];
echo "
<form id=\"form1\" name=\"form1\" method=\"post\" action=\"salvar_edicao.php\">
ID: <input name=\"id\" type=\"text\" readonly=\"readonly\" id=\"id\" value=\"$id\" size=\"35\"/><br>
CARRO: <input name=\"carro\" type=\"text\" id=\"id\" value=\"$carro\" size=\"35\"/><br>
DATA DE SAIDA: <input name=\"datasaida\" type=\"text\" id=\"id\" value=\"$datasaida\" size=\"35\"/><br>
HORA DE SAIDA: <input name=\"horasaida\" type=\"text\" id=\"id\" value=\"$horasaida\" size=\"35\"/><br>
DATA DE CHEGADA: <input name=\"datachegada\" type=\"text\" id=\"id\" value=\"$datachegada\" size=\"35\"/><br>
HORA DE CHEGADA: <input name=\"horachegada\" type=\"text\" id=\"id\" value=\"$horachegada\" size=\"30\"/><br>
KM INICIAL: <input name=\"kminicial\" type=\"text\" id=\"id\" value=\"$kminicial\" size=\"35\"/><br>
KM FINAL: <input name=\"kmfinal\" type=\"text\" id=\"id\" value=\"$kmfinal\" size=\"35\"/><br>
DESTINO: <input name=\"destino\" type=\"text\" id=\"id\" value=\"$destino\" size=\"35\"/><br>
MOTORISTA: <input name=\"motorista\" type=\"text\" id=\"id\" value=\"$motorista\" size=\"35\"/><br>
<input type=\"submit\" onclick=\"return confirm('Deseja mesmo editar esse registro?');\" name=\"Submit\" value=\"SALVAR ALTERAÇÕES\" class=\"btnNew\"/>
</form>
";
}
?>
You need a condition
WHERE
to be able to recover the data and the same to update the data.– Gnomo Escalate