douti9286 2016-12-01 11:48
浏览 16

将学生添加到组[重复]

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

</div>
  • 写回答

1条回答 默认 最新

  • dowjgrm6787 2016-12-01 11:56
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)