0
I’m a beginner in php and I’m trying to do a crud... in the edit button I made a function in js to appear the inputs and redirect to edit.php? id=echo $Row['id']..
CRUD - STUDENTS
Pupil Note Gang 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);
Not it :( , the problem is that it takes the last registered id, it even edits, but edits the last one
– Gustavo Pinheiro
n worked :d.
– Gustavo Pinheiro