如何通过文本框更新具有重复区域的 php mysql 中的多条记录?
用户应该输入他的学生的成绩,如果他点击提交按钮,成绩会在数据库中更新。
这是代码:
<?php
if(isset($_POST['enter'])){
foreach($_POST['StudentNo'] as $name => $value){
$MidGrade = $_POST['MidGrade'];
mysql_query("UPDATE grades SET MidGrade = '$MidGrade' WHERE StudentNo = '$value'")or die(mysql_error());
}
}
?>
<form id="form3" name="form3" method="post" action="array.php">
<table width="500" height="30" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="71">StudentNo</td>
<td width="500"><div align="center">Student Name </div></td>
<td width="127">MidGrade</td>
</tr>
<?php do { ?>
<tr>
<td>
<div align="center">
<input name="StudentNo" type="hidden" value="<?php echo $row_studentdetails['StudentNo']; ?>" size="10" />
<?php echo $row_studentdetails['StudentNo']; ?>
</div>
</td>
<td>
<div align="left">
<?php echo $row_studentdetails['LastName']; ?>
<?php echo $row_studentdetails['FirstName']; ?>
<?php echo $row_studentdetails['MiddleName']; ?>
</div>
</td>
<td>
<div align="center">
<input type="text" name="MidGrade" value="" size="10" />
</div>
</td>
</tr>
<?php } while ($row_studentdetails = mysql_fetch_assoc($studentdetails)); ?>
</table>
<p> </p>
<p align="center">
<input name="enter" type="submit" value="Insert record" />
</p>
</form>