gpt4 book ai didi

php - 多个复选框随行更新

转载 作者:行者123 更新时间:2023-11-29 18:36:27 25 4
gpt4 key购买 nike

i have this form

如何使用复选框按行更新此记录?该复选框保存我从先前表单发送的值。

this would be the database

这是对的吗?

while ($row = mysqli_fetch_array($result)){

。。。.

    <td><center>
<input type="hidden" name="matric[]" value="<?php echo $matric?>"/><p>
<input class="w3-check" type="checkbox" value='$hour' name="unattend<?php echo $matric?>[]">
<label> Unattend</label></p> </center></td>
<td><center>
<input type="hidden" name="matric[]" value="<?php echo $matric?>"/><p>
<input class="w3-check" type="checkbox" value='$hour' name="mc<?php echo $matric?>[]">
<label> I have MC </label></p> </center></td> }

更新mysql会怎样?

最佳答案

这是表格

<?php
$i = 1;
while ($row = mysqli_fetch_array($result)) {
$id=$row['matric_number'];
?>

<form method="POST" action="attend.php">
<tr>
<td><center><?php echo $i; ?></center></td>
<td><center><?php echo $row['student_name']; ?></center></td>
<td><center><?php echo $row['matric_number']; ?></center></td>
<td><center>
<p>
<input class="w3-check" name="unattend[]" type="checkbox" id="unattend[]" value="<?php echo $id; ?>">
<label> Unattend</label></p> </center></td>
<td><center>
<p>
<input class="w3-check" name="mc[]" type="checkbox" id="mc[]" value="<?php echo $id; ?>">
<label> I have MC </label></p> </center></td>
<td><center>
<?php echo "<a href=student.php?id1=".$row['matric_number'].">"."Details"; ?></center></td>



</tr>

<?php
$i++;
}


mysqli_close ($link);
?>
</table>

按行更新数据的php是

<?php
if (isset($_POST['unattend'])) {

$hour=$_POST['hour'];
$id=$_POST['unattend'];
$N = count($id);

for($i=0; $i < $N; $i++)
{
$select = mysqli_query($link,"SELECT * FROM pbu WHERE matric_number='$id[$i]'")or die(mysql_error());
while ($row = mysqli_fetch_array($select)) {

$value=$row['unattend'];
$total=$value+$hour;
$result = mysqli_query($link,"UPDATE pbu SET unattend='$total' WHERE matric_number='$id[$i]'")or die(mysql_error());
echo "unattend is updated for matric number ".$id[$i]."<br>";



}
}

}
if (isset($_POST['mc'])){
$id1=$_POST['mc'];
$N = count($id1);
for($i=0; $i < $N; $i++)
{
$select = mysqli_query($link,"SELECT * FROM pbu WHERE matric_number='$id[$i]'")or die(mysql_error());

while ($row = mysqli_fetch_array($select)) {

$values=$row['mc'];
$totals=$values+$hour;
$results = mysqli_query($link,"UPDATE pbu SET mc='$totals' WHERE matric_number='$id1[$i]'")or die(mysql_error());
echo "mc is updated for ".$id1[$i]."<br>";

}

}
}
else{
echo "nothing inserted";
}


?>

关于php - 多个复选框随行更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45255520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com