I am a beginner in php and I am trying to do a CRUD ... in the edit button I did a function in js to appear the inputs and redirect to edit.php? id = echo $ row ['id']; However, it only takes the last registered user ..
CRUD - STUDENTS
Student Note Class while($row = mysqli_fetch_assoc($listarAlunos)){
$id = $row['id'];
$nome = $row['nome'];
$nota = $row['nota'];
$turma = $row['turma'];
?>
<td>
<?php echo"$nome"?>
</td>
<td>
<?php echo"$nota"?>
</td>
<td>
<?php echo"$turma"?>
</td>
<td>
<button onclick="abrirEditar()">Editar</button>
<a href="remover.php?id=<?php echo $row['id'] ?>">
<button>Remover</button>
</a>
</td>
<tr></tr>
<script type="text/javascript">
function abrirEditar(){
var div = document.getElementById("divEditar");
div.innerHTML = "<br/><form method='post'>";
div.innerHTML+= "Novo Nome:<input type='text' name='novoNome'/><br/>";
div.innerHTML+= "Nova nota:<input type='text' name='novaNota'/><br/>";
div.innerHTML+= "Nova Turma:<input type='text' name='novaTurma'/><br/>";
div.innerHTML+= "<a href='editar.php?id=<?php echo $row['id'] ?>'><input type='submit' value='editar'/></a>";
div.innerHTML+="</form>";
}
</script>
<?php
}
?>
<div id="divEditar"></div>
</table>
</body>
edit.php
include 'conexao.php';
$id = $_GET['id'];
$novoNome = isset($_POST['novoNome']) ? $_POST['novoNome'] : '';
$novaNota = isset($_POST['novaNota']) ? $_POST['novaNota'] : '';
$novaTurma = isset($_POST['novaTurma']) ? $_POST['novaTurma'] : '';
echo $id;
$sql = "UPTADE tbaluno SET nome = '$novoNome', nota = '$novaNota', turma = '$novaTurma' WHERE id = $id";
$editarAluno = mysqli_query($conexao, $sql);