0

As a first little php mysql project I made a web app to keep records of my lessons as a guitar teacher. I made a form to add new students, and every lesson I make a few notes about the content of the lesson in another form.

The lessons are individual. A colleague would like to use the system, but his lessons are not individual. He has groups of 3 or 4 students.

I made a new table 'groups', a form to add a new group, and added a row 'group_id' in the student table. On my student_update page, I would like to add a select option to add a student to a group.

This is the code of the student_update page:

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

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

Everything worked fine until I added the group field. If I choose a group and hit update, I get the following error:

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

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

1 Answers1

1

Your dropdown menu has the name: groep and not groep_id. So $_POST['groep_id']; will never exist.

Loko
  • 6,539
  • 14
  • 50
  • 78