我的表格包含三列,即 Roll_No、Name 和 Marks。我正在从数据库中获取 Roll_no 和 Name。老师只需在表格中输入相应学生的卷号和姓名即可。我编码如下所示,但只有最后输入的值是为数据库中的所有学生设置的。它没有正确插入 sid 和滚动,但会产生标记问题。我的标记数据库结构是 sid、roll_no、marks。
这是我的代码:请纠正我哪里出错了。
<form method="post" action="">
<table width="900" height="49" border="1" cellpadding="0" cellspacing="0" align="center" >
<?php if(isset($_SESSION['response']))
{
echo "<tr><td colspan=\"7\">".$_SESSION['response']."</td></tr>"; unset($_SESSION['response']);} ?>
<tr>
<td align="center" width="20"> Roll No.</td>
<td align="center" width="200"> Name</td>
<td align="center" width="20"> Marks</td>
</tr>
<tr><input type="submit" name="next" value="submit" /></tr>
<?php
$sub = $_GET['sid'];
$result = mysql_query("select * from student_record_by_faculty where sid='$sub'");
$numrows = mysql_num_rows($result);
if($numrows!=0)
{
while($r=mysql_fetch_array($result))
{
$r2=mysql_fetch_array(mysql_query("select name from login where username='$r[reg_no]'"));
?>
<tr>
<td align="center"><?php echo $r['reg_no']; ?></td>
<td align="center"><?php echo $r2['name']; ?></td>
<td align="centre"><input type="number" name="marks" />
<?php
if(isset($_POST['next']))
{
$marks = $_POST['marks'];
$q=mysql_query("INSERT INTO marks(sid, reg_no, first_sessional) VALUES('$sub','$r[reg_no]','".$_POST['marks']."')");
echo $q;
if($q)
{ echo "marksheet updated you are being directed to marksheet page";
sleep(2);
header("Location:marksheet.php");
}
}
?>
</td></tr>
<?php
}
}
else
{
die('Error: ' . mysql_error());
}
//mysqli_close($con);*/
?>