2
I have a select that carries a series of records. Behold, in these records I need to apply an up and that, in my head, the best way would be using a checkbox field, so that when the user checked the checkbox and then clicked on the "send" button, only the checkbox field of all the records - would be updated at the same time (with 1or 2 depending on whether the field was marked 1 or not 2). Espe.. Thanks for your help! I’m racking my brain here and I’ve never been researching and asking and I didn’t get any conclusive answers
php form.
<?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'>
<input type='checkbox' name='presente' value='2'>
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?
You are creating a form per student, not correct
– user60252
I need help with that
– Claudio