作为第一个小型 php mysql 项目,我制作了一个网络应用程序来记录我作为吉他老师的类(class)。我制作了一个表格来添加新学生,每节课我都会用另一种形式对类(class)内容做一些笔记。
类(class)是针对个人的。一位同事想使用该系统,但他的类(class)不是针对个人的。他有 3 或 4 名学生组成的小组。
我创建了一个新表“groups”,一个用于添加新组的表单,并在学生表中添加了一行“group_id”。在我的 Student_update 页面上,我想添加一个选择选项以将学生添加到组中。
这是student_update页面的代码:
<?php
$q = "SELECT * FROM students WHERE uid = '$user[uid]' ORDER BY st_last ASC";//enkel velden ophalen van uid in kwestie
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
echo "<p>Om gegevens te wijzigen of aan te vullen kunt u gewoon in het desbetreffende veld typen en vervolgens op 'update' klikken.</p></br></br>
<table class='table'>
<thead>
<tr>
<th>Naam</th>
<th>Voornaam</th>
<th>Graad</th>
<th>Telefoon</th>
<th>Gsm</th>
<th>Email</th>
<th>Groep</th>
</tr>
</thead>";
while($student_list = mysqli_fetch_assoc($r)) { ?>
<tbody>
<form action="" method="POST" role="form">
<tr>
<input type="hidden" value="<?php echo $student_list['sid']?>" name="sid" />
<td width="8%"><input type="text" class="form-control" name="st_last" value="<?php echo $student_list['st_last']; ?>" /></td>
<td width="8%"><input type="text" class="form-control" name="st_first" value="<?php echo $student_list['st_first']; ?>"/></td>
<td width="3%"><input type="text" class="form-control" name="graad" value="<?php echo $student_list['graad']; ?>"/></td>
<td width="10%"><input type="text" class="form-control" name="vaste_telefoon" value="<?php echo $student_list['vaste_telefoon']; ?>"/></td>
<td width="10%"><input type="text" class="form-control" name="gsm" value="<?php echo $student_list['gsm']; ?>"/></td>
<td width="12%"><input type="text" class="form-control" name="email" value="<?php echo $student_list['email']; ?>"/></td>
<td width="11%"><div class="form-group">
<select class="form-control" name="groep" id="groep">
<option value="<>"></option>
<?php
$q2 = "SELECT * FROM Groepen ORDER BY groepsnaam ASC";
$r2 = mysqli_query($dbc, $q2);
while($groep_list = mysqli_fetch_assoc($r2)) {
?>
<option value="<?php echo $groep_list['groep_id']; ?>"><?php echo $groep_list['groepsnaam']; ?></option>
<?php } ?>
</select>
</div></td>
<td width="10%"> <div class="btn-group" role="group" aria-label="...">
<button type="submit" name="updatell" class="btn btn-warning">Update</button>
<button type="submit" name="deletell" class="btn btn-danger">Delete</button></td>
</tr>
</form>
</tbody>
<?php } }
else {
echo "U hebt nog geen leerlingen toegevoegd.";
}
?> </table>
更新:
<?php
if(isset($_POST['updatell'])) {
$qupdatestudent = "UPDATE students SET st_last='$_POST[st_last]', st_first='$_POST[st_first]', groep='$_POST[groep_id]', graad='$_POST[graad]', vaste_telefoon='$_POST[vaste_telefoon]', gsm='$_POST[gsm]', email='$_POST[email]' WHERE sid='$_POST[sid]'";
$r2 = mysqli_query($dbc, $qupdatestudent);
}
if(isset($_POST['deletell'])) {
$deletestudent = "DELETE FROM students WHERE sid='$_POST[sid]'";
$r3 = mysqli_query($dbc, $deletestudent);
}
?>
一切正常,直到我添加组字段。如果我选择一个组并点击更新,则会收到以下错误:
注意:未定义索引:/Applications/XAMPP/xamppfiles/htdocs/dummie/backend/leerlingenlijst.php 第 91 行中的 groep_id
最佳答案
您的下拉菜单的名称为:groep
,而不是groep_id
。所以 $_POST['groep_id'];
永远不会存在。
关于php - 将学生添加到组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40909915/