我正在为辅导中心创建一个学生登录网站。学生登录后,导师可以看到学生信息,导师也可以连同导师姓名一起提交学生信息。我的问题是无论我选择导师姓名,它总是插入最后一个导师姓名。我正在使用 PDO 进行数据库连接。请任何人都可以给我一个想法,我该如何解决这个问题。谢谢..
这是我的html表单代码:
<form action="" method="post">
<table border="1">
<tr>
<th>Student Name</th>
<th>course</th>
<th>Tutor</th>
<th>Actions</th>
</tr>
<?php
//select all users from database
$rows = $database->selectFromOnline();
foreach($rows as $row){
$time = $row['time_out'];
?>
<tr>
<td> <?php echo $row['user_name'] ?></td>
<td> <?php echo $row['course'] ?> </td>
<td>
<select name='tutor'>
<?php
//select all instructor from instructor table
$sqls = $database->selectFromTutor();
foreach($sqls as $sql){
echo"<option value='$sql[tutor_ln]'> $sql[tutor_ln] </option>";
}
?>
</select>
</td>
<?php
echo" <td> <a href='tutor.php?user_name=$row[user_name]&&course=$row[course]&&tutor=$sql[tutor_ln]'>Delete</a></td>";
?>
</tr>
<?php
}
?>
</table>
</form>
这是我的插入代码:
if(isset($_GET['user_name'])){
$user_name = $_GET['user_name'];
$course = $_GET['course'];
// if i use $_POST['tutor'] it gives me undefined variable error
$tutor = $_GET['tutor'];
//insert into report database table
$database->insetIntoReport($user_name, $course, $tutor);
//Redirect to current page
header('Location: tutor.php');
exit;
}
?>