2016-12-01 5 views
0

Als erstes kleines PHP mysql Projekt habe ich eine Web App erstellt, um Aufzeichnungen über meinen Unterricht als Gitarrenlehrer zu führen. Ich habe ein Formular erstellt, um neue Schüler hinzuzufügen, und in jeder Lektion mache ich ein paar Notizen über den Inhalt der Lektion in einer anderen Form.Studenten zur Gruppe hinzufügen

Die Lektionen sind individuell. Ein Kollege möchte das System benutzen, aber seine Lektionen sind nicht individuell. Er hat Gruppen von 3 oder 4 Studenten.

Ich habe eine neue Tabelle 'Gruppen', ein Formular zum Hinzufügen einer neuen Gruppe, und fügte eine Zeile 'group_id' in der Student-Tabelle. Auf meiner Seite student_update möchte ich eine Auswahloption hinzufügen, um einen Schüler einer Gruppe hinzuzufügen.

Dies ist der Code der student_update Seite:

<?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> 

Und für das Update:

<?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); 
    } 
?> 

Alles funktionierte gut, bis ich das Gruppenfeld hinzugefügt. Wenn ich eine Gruppe und treffen Update wählen, bekomme ich folgende Fehlermeldung:

Notice: Undefined index: groep_id in /Applications/XAMPP/xamppfiles/htdocs/dummie/backend/leerlingenlijst.php on line 91

+2

Ihr Dropdown-Menü hat den Namen: 'groep' und nicht' groep_id'.so '$ _POST ['groep_id'];' wird nie existieren. Oder lese ich es falsch? – Loko

+0

Das war in der Tat das Problem. Danke vielmals! –

Antwort

1

Ihre Dropdown-Menü hat den Namen: groep und nicht groep_id. Also $_POST['groep_id']; wird nie existieren.

Verwandte Themen