I have a student table where you have a presence field where present and are missing.
When I created the field, I left everyone as away , and now I need to list and change some to present . I would like to change all at once, but I do not know how to update
in all records at once.
form.php
<?php
$conn = mysqli_connect($servidor, $usuario, $senha, $dbname);
$idEvent = $_POST['idsubev'];
?>
<?php
//
$sql = "SELECT u.nome, e.titulo, a.presente, a.id_al FROM sch_usuarios u INNER JOIN sch_acontecimentos e INNER JOIN sch_aluno_acont a WHERE e.id_acon = a.id_acon AND u.id = a.id_al AND e.id_subevent='$idEvent' ORDER BY u.nome";
$query = mysqli_query($conn, $sql);
while ($rows = mysqli_fetch_array($query)) {
echo "
<form method='post' action = 'update.php' >
<input type='hidden' name='id' value='".$rows['id_al']."'>
<h1> Alterar presença do aluno</h1>
<table align='' border='0' bordercolor='#BCBCBC' cellspacing='0'>
<tr align ='left' bordercolor='#000000' >
<td valign='middle'> </td>
<td valign='middle'> </td>
</tr>
<tr align ='left' bordercolor='#000000' ><td valign='middle' bgcolor='#E9E9E9'><p><font color=''>Nome:</font> </p></td>
<td align='left' valign='middle' bgcolor='#E9E9E9'><input type = 'text' size='50' name='nome' value ='".$rows['nome']."'></td>
</tr>
<tr><td><font color=''> Curso: </font> </td>
<td align='left'><input type='text' size='30' name='curso' value=' ".$rows['titulo']."'><font color=''> </font>
</td>
<tr align ='left'>
//QUERO ATUALIZAR ESSE CAMPOS ABAIXO CHAMADO PRESENTE
<td><font color=''>Presente=<b>".$rows['presente']."</b> </font></td>
<td align='left'>
//AQUI MARCAREI O CHECKBOX NOS ALUNOS QUE QUERO MUDAR PARA 1 (PRESENTE)
Status 1= presente, 2= ausente
<input type='checkbox' name='presente' value='1'>Marcar Presente?
</td>
</tr>
</table>
"; /*fecha a tabela apos termino de impressão das linhas*/
}
echo "<input type='submit' value='alterar'>
</form>";
?>
update.php
$id=$_POST['id'];
$presente = $_POST['presente'];
$mysqli = new mysqli('localhost', 'wwwcard_ew3', 'adm22334455', 'wwwcard_ew3');
$sql = "UPDATE sch_aluno_acont SET presente = '$presente' WHERE id_al = '$id'";
$stmt = $mysqli->prepare($sql) or die($mysqli->error);
if(!$stmt){
echo 'erro na consulta: '. $mysqli->errno .' - '. $mysqli->error;
}
$stmt->bind_param('ssi',$id, $presente);
$stmt->execute();
header("Location: index.php?altera_aluno");