2016-12-01 56 views
0

作为第一个小型的php项目,我制作了一个网络应用程序来保存我作为吉他老师的课程记录。我制作了一个表格来添加新的学生,每节课我都会以另一种形式对课程内容做一些说明。将学生添加到群组

课程是个人的。一位同事想要使用该系统,但他的课程不是个人的。他有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 groep_id上线91

+2

您的下拉菜单的名称是:'groep'而不是'groep_id'.so'$ _POST ['groep_id'];'永远不会存在。还是我读错了? – Loko

+0

确实是这个问题。非常感谢! –

回答

1

你下拉菜单的名称是:groep,而不是groep_id。所以$_POST['groep_id'];将永远不会存在。